Skip to content

Commit

Permalink
feat: init project base
Browse files Browse the repository at this point in the history
  • Loading branch information
enestatli committed Sep 23, 2024
1 parent bf60246 commit 9059344
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 33 deletions.
39 changes: 9 additions & 30 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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<number | undefined>();

useEffect(() => {
multiply(3, 7).then(setResult);
}, []);

return (
<View style={styles.container}>
<Text>Result: {result}</Text>
</View>
);
}

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);
});
33 changes: 33 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<LoginResult>;
handleLoginResult: (
intentUri: string,
redirectUri: string
) => Promise<LoginResult>;
share: (
clientKey: string,
mediaUrls: string[],
isImage: boolean,
isGreenScreen: boolean
) => Promise<void>;
handleShareResult: (intentUri: string) => Promise<ShareResult>;
grantUriPermission: (uri: string) => Promise<void>;
}

declare const TikTokSDK: TikTokSDKType;

export default TikTokSDK;
23 changes: 20 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoginResult>;
handleLoginResult: (
intentUri: string,
redirectUri: string
) => Promise<LoginResult>;
share: (
clientKey: string,
mediaUrls: string[],
isImage: boolean,
isGreenScreen: boolean
) => Promise<void>;
handleShareResult: (intentUri: string) => Promise<ShareResult>;
grantUriPermission: (uri: string) => Promise<void>;
}

const TikTokSDK: TikTokSDKType = {
login: (clientKey: string, redirectUri: string): Promise<LoginResult> => {
return TiktokOpensdkReactNative.login(clientKey, redirectUri);
},
Expand Down

0 comments on commit 9059344

Please sign in to comment.