From 9059344c7df285fec92caaf2288f891803ac0a9d Mon Sep 17 00:00:00 2001 From: enestatli Date: Mon, 23 Sep 2024 14:49:15 +0300 Subject: [PATCH] feat: init project base --- example/src/App.tsx | 39 +++++++++------------------------------ src/index.d.ts | 33 +++++++++++++++++++++++++++++++++ src/index.tsx | 23 ++++++++++++++++++++--- 3 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 src/index.d.ts diff --git a/example/src/App.tsx b/example/src/App.tsx index 71919cb..c06d095 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,30 +1,9 @@ -import { useState, useEffect } from 'react'; -import { StyleSheet, View, Text } from 'react-native'; -import { multiply } from 'tiktok-opensdk-react-native'; - -export default function App() { - const [result, setResult] = useState(); - - useEffect(() => { - multiply(3, 7).then(setResult); - }, []); - - return ( - - Result: {result} - - ); -} - -const styles = StyleSheet.create({ - container: { - flex: 1, - alignItems: 'center', - justifyContent: 'center', - }, - box: { - width: 60, - height: 60, - marginVertical: 20, - }, -}); +import TikTokSDK from 'tiktok-opensdk-react-native'; + +TikTokSDK.login('your-client-key', 'your-redirect-uri') + .then((result) => { + console.log(result); + }) + .catch((error) => { + console.error(error); + }); diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..caee76c --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,33 @@ +export interface LoginResult { + authCode: string; + grantedPermissions: string[]; + authError?: string; + authErrorDescription?: string; +} + +export interface ShareResult { + isSuccess: boolean; + errorCode: number; + subErrorCode: number; + errorMsg: string; +} + +export interface TikTokSDKType { + login: (clientKey: string, redirectUri: string) => Promise; + handleLoginResult: ( + intentUri: string, + redirectUri: string + ) => Promise; + share: ( + clientKey: string, + mediaUrls: string[], + isImage: boolean, + isGreenScreen: boolean + ) => Promise; + handleShareResult: (intentUri: string) => Promise; + grantUriPermission: (uri: string) => Promise; +} + +declare const TikTokSDK: TikTokSDKType; + +export default TikTokSDK; diff --git a/src/index.tsx b/src/index.tsx index bcd9d1c..f7132bc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -16,21 +16,38 @@ const TiktokOpensdkReactNative = NativeModules.TiktokOpensdkReactNative }, } ); -interface LoginResult { + +export interface LoginResult { authCode: string; grantedPermissions: string[]; authError?: string; authErrorDescription?: string; } -interface ShareResult { +export interface ShareResult { isSuccess: boolean; errorCode: number; subErrorCode: number; errorMsg: string; } -const TikTokSDK = { +export interface TikTokSDKType { + login: (clientKey: string, redirectUri: string) => Promise; + handleLoginResult: ( + intentUri: string, + redirectUri: string + ) => Promise; + share: ( + clientKey: string, + mediaUrls: string[], + isImage: boolean, + isGreenScreen: boolean + ) => Promise; + handleShareResult: (intentUri: string) => Promise; + grantUriPermission: (uri: string) => Promise; +} + +const TikTokSDK: TikTokSDKType = { login: (clientKey: string, redirectUri: string): Promise => { return TiktokOpensdkReactNative.login(clientKey, redirectUri); },