Skip to content

Commit

Permalink
feat: 优化ShareUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Damoness committed Mar 25, 2021
1 parent e042055 commit 22f9cb5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
29 changes: 27 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { StyleSheet, View, Button } from 'react-native';
import { StyleSheet, View, Button, Alert } from 'react-native';
import { ShareUtil, Platform } from '@damoness/react-native-umeng';

export default function App() {
Expand All @@ -12,11 +12,23 @@ export default function App() {
try {
let re = await ShareUtil.auth(Platform.Wechat);
console.log(re);
Alert.alert(JSON.stringify(re));
} catch (error) {
console.log('error', error);
}
}}
/>
<Button
title={'微信登录 报错'}
onPress={async () => {
try {
await ShareUtil.auth(Platform.Wechat + 2);
} catch (error) {
console.log('error', error);
Alert.alert(JSON.stringify(error));
}
}}
/>
<Button
onPress={() => {
ShareUtil.shareboard(
Expand All @@ -27,7 +39,20 @@ export default function App() {
[Platform.Wechat, Platform.Wechat_TimeLine]
);
}}
title="分享面板"
title="分享面板 - 分享"
/>

<Button
onPress={() => {
ShareUtil.shareboard(
'内容',
'http://t1.qichangv.com/images/logo/favition.png',
'',
'标题',
[Platform.Wechat, Platform.Wechat_TimeLine]
);
}}
title="分享面板 - 分享图片"
/>
</View>
);
Expand Down
14 changes: 7 additions & 7 deletions src/ShareUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ export default class ShareUtil {
link: string,
title: string,
platforms: Platform[]
) {
): Promise<String> {
return new Promise((resolve, reject) => {
ShareModule.shareboard(
text,
icon,
link,
title,
platforms,
(code: number, result: any, message: string) => {
code === 200 ? resolve(result) : reject(message);
(code: number, message: string) => {
code === 200 ? resolve(message) : reject(message);
}
);
});
Expand All @@ -87,20 +87,20 @@ export default class ShareUtil {
link: string,
title: string,
platform: Platform
) {
): Promise<string> {
return new Promise((resolve, reject) => {
ShareModule.share(
text,
icon,
link,
title,
platform,
(code: number, result: any, message: string) => {
(code: number, message: string) => {
if (code === 200) {
//成功
resolve(result);
resolve(message);
} else {
console.log(code, result, message);
console.log(code, message);
reject(message);
}
}
Expand Down

0 comments on commit 22f9cb5

Please sign in to comment.