@utae/react-native-kakao-share-link
Version:
리액트 네이티브로 사용하는 카카오톡으로 공유하기. Kakao SDK v2를 사용한 카카오 링크(공유).
165 lines (148 loc) • 4.16 kB
JavaScript
import { NativeModules, Platform } from 'react-native';
const {
KakaoShareLink
} = NativeModules;
/**
* ContentType
* @description 카카오 링크 본문 내용 타입
* @property title 제목
* @property imageUrl 이미지 url
* @property link 클릭 시 열리는 링크
* @property description 설명 (Option)
* @property imageWidth 이미지 가로 길이 (Option)
* @property imageHeight 이미지 세로 길이 (Option)
*/
/**
* BrowserNotFoundError
* @description 카카오톡 미설치 시 브라우저를 통해 공유하기 기능이 실행되는데 브라우저를 찾지 못한 경우 발생하는 에러
*/
export class BrowserNotFoundError extends Error {}
const ANDROID_BROWSER_NOT_FOUND_ERROR_CODE = 'E_KAKAO_NO_BROWSER';
const handleError = ({
error,
callback
}) => {
if (callback && typeof callback === 'function') {
callback(error, undefined);
}
if (Platform.OS === 'android' && error.code === ANDROID_BROWSER_NOT_FOUND_ERROR_CODE) {
throw new BrowserNotFoundError();
}
throw error;
};
/**
* sendCommerce
* @param {CommerceTemplateType} commerceTemplate CommerceTemplate Item
* @param {CallbackType} [callback] callback function
* @returns {Promise<SendResultType>}
*/
export const sendCommerce = (commerceTemplate, callback) => {
return KakaoShareLink.sendCommerce(commerceTemplate).then(result => {
if (callback && typeof callback === 'function') {
callback(undefined, result);
}
return result;
}).catch(error => {
handleError({
error,
callback
});
});
};
/**
* sendList
* @param {ListTemplateType} listTemplate ListTemplate Item
* @param {CallbackType} [callback] callback function
* @returns {Promise<SendResultType>}
*/
export const sendList = (listTemplate, callback) => {
return KakaoShareLink.sendList(listTemplate).then(result => {
if (callback && typeof callback === 'function') {
callback(undefined, result);
}
return result;
}).catch(error => {
handleError({
error,
callback
});
});
};
/**
* sendFeed
* @param {FeedTemplateType} feedTemplate FeedTemplate Item
* @param {CallbackType} [callback] callback function
* @returns {Promise<SendResultType>}
*/
export const sendFeed = (feedTemplate, callback) => {
return KakaoShareLink.sendFeed(feedTemplate).then(result => {
if (callback && typeof callback === 'function') {
callback(undefined, result);
}
return result;
}).catch(error => {
handleError({
error,
callback
});
});
};
/**
* sendText
* @param {TextTemplateType} textTemplate TextTemplate Item
* @param {CallbackType} [callback] callback function
* @returns {Promise<SendResultType>}
*/
export const sendText = (textTemplate, callback) => {
return KakaoShareLink.sendText(textTemplate).then(result => {
if (callback && typeof callback === 'function') {
callback(undefined, result);
}
return result;
}).catch(error => {
handleError({
error,
callback
});
});
};
/**
* sendLocation
* @param {LocationTemplateType} locationTemplate LocationTemplate Item
* @param {CallbackType} [callback] callback function
* @returns {Promise<SendResultType>}
*/
export const sendLocation = (locationTemplate, callback) => {
return KakaoShareLink.sendLocation(locationTemplate).then(result => {
if (callback && typeof callback === 'function') {
callback(undefined, result);
}
return result;
}).catch(error => {
handleError({
error,
callback
});
});
};
/**
* sendCustom
* @param {CustomTemplateType} customTemplate CustomTemplate Item
* @param {CallbackType} [callback] callback function
* @returns {Promise<SendResultType>}
*/
export const sendCustom = (customTemplate, callback) => {
return KakaoShareLink.sendCustom(customTemplate).then(result => {
if (callback && typeof callback === 'function') {
callback(undefined, result);
}
return result;
}).catch(error => {
handleError({
error,
callback
});
});
};
export default KakaoShareLink;
//# sourceMappingURL=index.js.map