Showing
8 changed files
with
164 additions
and
94 deletions
| @@ -8,111 +8,128 @@ | @@ -8,111 +8,128 @@ | ||
| 8 | * @format | 8 | * @format |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | -import React from 'react'; | 11 | +import React, { useState, useEffect } from 'react'; |
| 12 | import { | 12 | import { |
| 13 | SafeAreaView, | 13 | SafeAreaView, |
| 14 | - StyleSheet, | 14 | + Button, |
| 15 | + NativeModules, | ||
| 16 | + Picker, | ||
| 15 | ScrollView, | 17 | ScrollView, |
| 16 | - View, | 18 | + Platform, |
| 17 | - Text, | ||
| 18 | - StatusBar, | ||
| 19 | } from 'react-native'; | 19 | } from 'react-native'; |
| 20 | +import { Text, ListItem, Card } from 'react-native-elements'; | ||
| 21 | +import Wechat, { WXShareType, WXShareScene } from './src'; | ||
| 20 | 22 | ||
| 21 | -import { | 23 | +const { BCWechat } = NativeModules; |
| 22 | - Header, | 24 | +Wechat.registerApp('wx32beae1b4606079a', 'https://pm.yfchangketong.com/'); |
| 23 | - LearnMoreLinks, | ||
| 24 | - Colors, | ||
| 25 | - DebugInstructions, | ||
| 26 | - ReloadInstructions, | ||
| 27 | -} from 'react-native/Libraries/NewAppScreen'; | ||
| 28 | - | ||
| 29 | -declare var global: {HermesInternal: null | {}}; | ||
| 30 | 25 | ||
| 31 | const App = () => { | 26 | const App = () => { |
| 27 | + const [err, setErr] = useState<Error>(); | ||
| 28 | + const [version, setVersion] = useState(''); | ||
| 29 | + const [isWXInstalled, setIsWXInstalled] = useState(false); | ||
| 30 | + const [apiLevel, setApiLevel] = useState<number | boolean>(); | ||
| 31 | + const [scene, setScene] = useState(WXShareScene.WXSceneSession); | ||
| 32 | + | ||
| 33 | + const constants = BCWechat.getConstants(); | ||
| 34 | + | ||
| 35 | + useEffect(() => { | ||
| 36 | + Wechat.getApiVersion().then(setVersion); | ||
| 37 | + Wechat.isWXAppInstalled().then(setIsWXInstalled); | ||
| 38 | + if (Platform.OS === 'android') { | ||
| 39 | + Wechat.getWXAppSupportAPI().then(setApiLevel); | ||
| 40 | + } else { | ||
| 41 | + Wechat.isWXAppSupportApi().then(setApiLevel); | ||
| 42 | + } | ||
| 43 | + }, []); | ||
| 32 | return ( | 44 | return ( |
| 33 | - <> | 45 | + <SafeAreaView style={{ flex: 1 }}> |
| 34 | - <StatusBar barStyle="dark-content" /> | 46 | + <Card> |
| 35 | - <SafeAreaView> | 47 | + <Text h4>Error</Text> |
| 48 | + <Text>{`${err?.message}`}</Text> | ||
| 49 | + </Card> | ||
| 36 | <ScrollView | 50 | <ScrollView |
| 51 | + style={{ flex: 1 }} | ||
| 37 | contentInsetAdjustmentBehavior="automatic" | 52 | contentInsetAdjustmentBehavior="automatic" |
| 38 | - style={styles.scrollView}> | 53 | + > |
| 39 | - <Header /> | 54 | + <Text h4>Native</Text> |
| 40 | - {global.HermesInternal == null ? null : ( | 55 | + {Object.keys(BCWechat).map((k, i) => ( |
| 41 | - <View style={styles.engine}> | 56 | + <Text key={i}>{k}</Text> |
| 42 | - <Text style={styles.footer}>Engine: Hermes</Text> | 57 | + ))} |
| 43 | - </View> | 58 | + <Text h4>Info</Text> |
| 44 | - )} | 59 | + <ListItem title="version" rightTitle={version} /> |
| 45 | - <View style={styles.body}> | 60 | + <ListItem title="wx installed" rightTitle={`${isWXInstalled}`} /> |
| 46 | - <View style={styles.sectionContainer}> | 61 | + <ListItem title="api support" rightTitle={`${apiLevel}`} /> |
| 47 | - <Text style={styles.sectionTitle}>Step One</Text> | 62 | + <Text h4>Constants</Text> |
| 48 | - <Text style={styles.sectionDescription}> | 63 | + {Object.keys(constants).map((k, i) => ( |
| 49 | - Edit <Text style={styles.highlight}>App.tsx</Text> to change | 64 | + <ListItem key={k} title={k} rightTitle={`${constants[k]}`} /> |
| 50 | - this screen and then come back to see your edits. | 65 | + ))} |
| 51 | - </Text> | 66 | + <Button title="open WX" onPress={Wechat.openWXApp} /> |
| 52 | - </View> | 67 | + <Text h4>分享</Text> |
| 53 | - <View style={styles.sectionContainer}> | 68 | + <Picker selectedValue={scene} onValueChange={v => setScene(v)}> |
| 54 | - <Text style={styles.sectionTitle}>See Your Changes</Text> | 69 | + <Picker.Item label="对话" value={WXShareScene.WXSceneSession} /> |
| 55 | - <Text style={styles.sectionDescription}> | 70 | + <Picker.Item label="朋友圈" value={WXShareScene.WXSceneTimeline} /> |
| 56 | - <ReloadInstructions /> | 71 | + <Picker.Item label="收藏" value={WXShareScene.WXSceneFavorite} /> |
| 57 | - </Text> | 72 | + </Picker> |
| 58 | - </View> | 73 | + <Button |
| 59 | - <View style={styles.sectionContainer}> | 74 | + title="分享文字" |
| 60 | - <Text style={styles.sectionTitle}>Debug</Text> | 75 | + onPress={() => { |
| 61 | - <Text style={styles.sectionDescription}> | 76 | + Wechat.shareMessage({ |
| 62 | - <DebugInstructions /> | 77 | + type: WXShareType.WXShareTypeText, |
| 63 | - </Text> | 78 | + text: 'Some test text', |
| 64 | - </View> | 79 | + scene, |
| 65 | - <View style={styles.sectionContainer}> | 80 | + }) |
| 66 | - <Text style={styles.sectionTitle}>Learn More</Text> | 81 | + .then(resp => { |
| 67 | - <Text style={styles.sectionDescription}> | 82 | + console.log(resp); |
| 68 | - Read the docs to discover what to do next: | 83 | + }) |
| 69 | - </Text> | 84 | + .catch(setErr); |
| 70 | - </View> | 85 | + }} |
| 71 | - <LearnMoreLinks /> | 86 | + /> |
| 72 | - </View> | 87 | + <Button |
| 88 | + title="分享图片" | ||
| 89 | + onPress={() => { | ||
| 90 | + Wechat.shareMessage({ | ||
| 91 | + type: WXShareType.WXShareTypeImage, | ||
| 92 | + title: '标题', | ||
| 93 | + description: '描述', | ||
| 94 | + thumbUrl: '', | ||
| 95 | + scene, | ||
| 96 | + imageUrl: | ||
| 97 | + 'https://i0.hdslb.com/bfs/archive/45b8d2f84ec662df05b829bbe866cf620833cce5.jpg@412w_232h_1c_100q.jpg', | ||
| 98 | + }); | ||
| 99 | + }} | ||
| 100 | + /> | ||
| 101 | + <Button | ||
| 102 | + title="分享音乐" | ||
| 103 | + onPress={() => { | ||
| 104 | + Wechat.shareMessage({ | ||
| 105 | + type: WXShareType.WXShareTypeMusic, | ||
| 106 | + musicUrl: 'https://music.163.com/#/song?id=1410448577', | ||
| 107 | + title: '标题', | ||
| 108 | + description: '描述', | ||
| 109 | + thumbUrl: | ||
| 110 | + 'https://i0.hdslb.com/bfs/archive/45b8d2f84ec662df05b829bbe866cf620833cce5.jpg@412w_232h_1c_100q.jpg', | ||
| 111 | + scene, | ||
| 112 | + }); | ||
| 113 | + }} | ||
| 114 | + /> | ||
| 115 | + <Button | ||
| 116 | + title="分享视频" | ||
| 117 | + onPress={() => { | ||
| 118 | + Wechat.shareMessage({ | ||
| 119 | + type: WXShareType.WXShareTypeVideo, | ||
| 120 | + videoUrl: | ||
| 121 | + 'https://www.bilibili.com/video/BV1o7411177j?spm_id_from=333.851.b_7265706f7274466972737431.8', | ||
| 122 | + title: '标题', | ||
| 123 | + description: '描述', | ||
| 124 | + thumbUrl: | ||
| 125 | + 'https://i0.hdslb.com/bfs/archive/45b8d2f84ec662df05b829bbe866cf620833cce5.jpg@412w_232h_1c_100q.jpg', | ||
| 126 | + scene, | ||
| 127 | + }); | ||
| 128 | + }} | ||
| 129 | + /> | ||
| 73 | </ScrollView> | 130 | </ScrollView> |
| 74 | </SafeAreaView> | 131 | </SafeAreaView> |
| 75 | - </> | ||
| 76 | ); | 132 | ); |
| 77 | }; | 133 | }; |
| 78 | 134 | ||
| 79 | -const styles = StyleSheet.create({ | ||
| 80 | - scrollView: { | ||
| 81 | - backgroundColor: Colors.lighter, | ||
| 82 | - }, | ||
| 83 | - engine: { | ||
| 84 | - position: 'absolute', | ||
| 85 | - right: 0, | ||
| 86 | - }, | ||
| 87 | - body: { | ||
| 88 | - backgroundColor: Colors.white, | ||
| 89 | - }, | ||
| 90 | - sectionContainer: { | ||
| 91 | - marginTop: 32, | ||
| 92 | - paddingHorizontal: 24, | ||
| 93 | - }, | ||
| 94 | - sectionTitle: { | ||
| 95 | - fontSize: 24, | ||
| 96 | - fontWeight: '600', | ||
| 97 | - color: Colors.black, | ||
| 98 | - }, | ||
| 99 | - sectionDescription: { | ||
| 100 | - marginTop: 8, | ||
| 101 | - fontSize: 18, | ||
| 102 | - fontWeight: '400', | ||
| 103 | - color: Colors.dark, | ||
| 104 | - }, | ||
| 105 | - highlight: { | ||
| 106 | - fontWeight: '700', | ||
| 107 | - }, | ||
| 108 | - footer: { | ||
| 109 | - color: Colors.dark, | ||
| 110 | - fontSize: 12, | ||
| 111 | - fontWeight: '600', | ||
| 112 | - padding: 4, | ||
| 113 | - paddingRight: 12, | ||
| 114 | - textAlign: 'right', | ||
| 115 | - }, | ||
| 116 | -}); | ||
| 117 | - | ||
| 118 | export default App; | 135 | export default App; |
| 1 | apply plugin: "com.android.application" | 1 | apply plugin: "com.android.application" |
| 2 | +apply plugin: 'kotlin-android-extensions' | ||
| 3 | +apply plugin: 'kotlin-android' | ||
| 2 | 4 | ||
| 3 | import com.android.build.OutputFile | 5 | import com.android.build.OutputFile |
| 4 | 6 | ||
| @@ -191,6 +193,8 @@ dependencies { | @@ -191,6 +193,8 @@ dependencies { | ||
| 191 | } else { | 193 | } else { |
| 192 | implementation jscFlavor | 194 | implementation jscFlavor |
| 193 | } | 195 | } |
| 196 | + implementation "androidx.core:core-ktx:+" | ||
| 197 | + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
| 194 | } | 198 | } |
| 195 | 199 | ||
| 196 | // Run this once to be able to run the application with BUCK | 200 | // Run this once to be able to run the application with BUCK |
| @@ -201,3 +205,6 @@ task copyDownloadableDepsToLibs(type: Copy) { | @@ -201,3 +205,6 @@ task copyDownloadableDepsToLibs(type: Copy) { | ||
| 201 | } | 205 | } |
| 202 | 206 | ||
| 203 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) | 207 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) |
| 208 | +repositories { | ||
| 209 | + mavenCentral() | ||
| 210 | +} |
| 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. | 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. |
| 2 | 2 | ||
| 3 | buildscript { | 3 | buildscript { |
| 4 | + ext.kotlin_version = '1.3.71' | ||
| 4 | ext { | 5 | ext { |
| 5 | buildToolsVersion = "28.0.3" | 6 | buildToolsVersion = "28.0.3" |
| 6 | minSdkVersion = 16 | 7 | minSdkVersion = 16 |
| @@ -13,6 +14,7 @@ buildscript { | @@ -13,6 +14,7 @@ buildscript { | ||
| 13 | } | 14 | } |
| 14 | dependencies { | 15 | dependencies { |
| 15 | classpath("com.android.tools.build:gradle:3.4.2") | 16 | classpath("com.android.tools.build:gradle:3.4.2") |
| 17 | + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
| 16 | 18 | ||
| 17 | // NOTE: Do not place your application dependencies here; they belong | 19 | // NOTE: Do not place your application dependencies here; they belong |
| 18 | // in the individual module build.gradle files | 20 | // in the individual module build.gradle files |
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | 9 | ||
| 10 | #import <React/RCTBridge.h> | 10 | #import <React/RCTBridge.h> |
| 11 | #import <React/RCTBundleURLProvider.h> | 11 | #import <React/RCTBundleURLProvider.h> |
| 12 | +#import <React/RCTLinkingManager.h> | ||
| 12 | #import <React/RCTRootView.h> | 13 | #import <React/RCTRootView.h> |
| 13 | 14 | ||
| 14 | @implementation AppDelegate | 15 | @implementation AppDelegate |
| @@ -39,4 +40,16 @@ | @@ -39,4 +40,16 @@ | ||
| 39 | #endif | 40 | #endif |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 43 | +// ios 9.0+ | ||
| 44 | +- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url | ||
| 45 | + options:(NSDictionary<NSString*, id> *)options | ||
| 46 | +{ | ||
| 47 | + return [RCTLinkingManager application:application openURL:url options:options]; | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler | ||
| 51 | +{ | ||
| 52 | + return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; | ||
| 53 | +} | ||
| 54 | + | ||
| 42 | @end | 55 | @end |
| @@ -20,8 +20,29 @@ | @@ -20,8 +20,29 @@ | ||
| 20 | <string>1.0</string> | 20 | <string>1.0</string> |
| 21 | <key>CFBundleSignature</key> | 21 | <key>CFBundleSignature</key> |
| 22 | <string>????</string> | 22 | <string>????</string> |
| 23 | + <key>CFBundleURLTypes</key> | ||
| 24 | + <array> | ||
| 25 | + <dict> | ||
| 26 | + <key>CFBundleTypeRole</key> | ||
| 27 | + <string>Editor</string> | ||
| 28 | + <key>CFBundleURLName</key> | ||
| 29 | + <string>weixin</string> | ||
| 30 | + <key>CFBundleURLSchemes</key> | ||
| 31 | + <array> | ||
| 32 | + <string>wx32beae1b4606079a</string> | ||
| 33 | + </array> | ||
| 34 | + </dict> | ||
| 35 | + </array> | ||
| 23 | <key>CFBundleVersion</key> | 36 | <key>CFBundleVersion</key> |
| 24 | <string>1</string> | 37 | <string>1</string> |
| 38 | + <key>LSApplicationCategoryType</key> | ||
| 39 | + <string></string> | ||
| 40 | + <key>LSApplicationQueriesSchemes</key> | ||
| 41 | + <array> | ||
| 42 | + <string>weixin</string> | ||
| 43 | + <string>wechat</string> | ||
| 44 | + <string>weixinULAPI</string> | ||
| 45 | + </array> | ||
| 25 | <key>LSRequiresIPhoneOS</key> | 46 | <key>LSRequiresIPhoneOS</key> |
| 26 | <true/> | 47 | <true/> |
| 27 | <key>NSAppTransportSecurity</key> | 48 | <key>NSAppTransportSecurity</key> |
| @@ -219,6 +219,8 @@ PODS: | @@ -219,6 +219,8 @@ PODS: | ||
| 219 | - React-cxxreact (= 0.61.5) | 219 | - React-cxxreact (= 0.61.5) |
| 220 | - React-jsi (= 0.61.5) | 220 | - React-jsi (= 0.61.5) |
| 221 | - ReactCommon/jscallinvoker (= 0.61.5) | 221 | - ReactCommon/jscallinvoker (= 0.61.5) |
| 222 | + - rn-wechat (0.0.2): | ||
| 223 | + - React | ||
| 222 | - RNCMaskedView (0.1.7): | 224 | - RNCMaskedView (0.1.7): |
| 223 | - React | 225 | - React |
| 224 | - RNGestureHandler (1.6.0): | 226 | - RNGestureHandler (1.6.0): |
| @@ -260,6 +262,7 @@ DEPENDENCIES: | @@ -260,6 +262,7 @@ DEPENDENCIES: | ||
| 260 | - React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`) | 262 | - React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`) |
| 261 | - ReactCommon/jscallinvoker (from `../node_modules/react-native/ReactCommon`) | 263 | - ReactCommon/jscallinvoker (from `../node_modules/react-native/ReactCommon`) |
| 262 | - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) | 264 | - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) |
| 265 | + - rn-wechat (from `../../rn-wechat`) | ||
| 263 | - "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)" | 266 | - "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)" |
| 264 | - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) | 267 | - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) |
| 265 | - RNReanimated (from `../node_modules/react-native-reanimated`) | 268 | - RNReanimated (from `../node_modules/react-native-reanimated`) |
| @@ -322,6 +325,8 @@ EXTERNAL SOURCES: | @@ -322,6 +325,8 @@ EXTERNAL SOURCES: | ||
| 322 | :path: "../node_modules/react-native/Libraries/Vibration" | 325 | :path: "../node_modules/react-native/Libraries/Vibration" |
| 323 | ReactCommon: | 326 | ReactCommon: |
| 324 | :path: "../node_modules/react-native/ReactCommon" | 327 | :path: "../node_modules/react-native/ReactCommon" |
| 328 | + rn-wechat: | ||
| 329 | + :path: "../../rn-wechat" | ||
| 325 | RNCMaskedView: | 330 | RNCMaskedView: |
| 326 | :path: "../node_modules/@react-native-community/masked-view" | 331 | :path: "../node_modules/@react-native-community/masked-view" |
| 327 | RNGestureHandler: | 332 | RNGestureHandler: |
| @@ -362,6 +367,7 @@ SPEC CHECKSUMS: | @@ -362,6 +367,7 @@ SPEC CHECKSUMS: | ||
| 362 | React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe | 367 | React-RCTText: 9ccc88273e9a3aacff5094d2175a605efa854dbe |
| 363 | React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad | 368 | React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad |
| 364 | ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd | 369 | ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd |
| 370 | + rn-wechat: 8ef41be3d91557dbf900678c1d86beda86e08f00 | ||
| 365 | RNCMaskedView: 76c40a1d41c3e2535df09246a2b5487f04de0814 | 371 | RNCMaskedView: 76c40a1d41c3e2535df09246a2b5487f04de0814 |
| 366 | RNGestureHandler: dde546180bf24af0b5f737c8ad04b6f3fa51609a | 372 | RNGestureHandler: dde546180bf24af0b5f737c8ad04b6f3fa51609a |
| 367 | RNReanimated: 031fe8d9ea93c2bd689a40f05320ef9d96f74d7f | 373 | RNReanimated: 031fe8d9ea93c2bd689a40f05320ef9d96f74d7f |
| @@ -371,4 +377,4 @@ SPEC CHECKSUMS: | @@ -371,4 +377,4 @@ SPEC CHECKSUMS: | ||
| 371 | 377 | ||
| 372 | PODFILE CHECKSUM: ad4c3998d58868407224af05ed79c54dc0c9aa70 | 378 | PODFILE CHECKSUM: ad4c3998d58868407224af05ed79c54dc0c9aa70 |
| 373 | 379 | ||
| 374 | -COCOAPODS: 1.8.3 | 380 | +COCOAPODS: 1.9.1 |
| @@ -25,7 +25,8 @@ | @@ -25,7 +25,8 @@ | ||
| 25 | "react-native-safe-area-context": "^0.7.3", | 25 | "react-native-safe-area-context": "^0.7.3", |
| 26 | "react-native-screens": "^2.2.0", | 26 | "react-native-screens": "^2.2.0", |
| 27 | "react-native-tab-view": "^2.13.0", | 27 | "react-native-tab-view": "^2.13.0", |
| 28 | - "react-native-vector-icons": "^6.6.0" | 28 | + "react-native-vector-icons": "^6.6.0", |
| 29 | + "rn-wechat": "file:../rn-wechat" | ||
| 29 | }, | 30 | }, |
| 30 | "devDependencies": { | 31 | "devDependencies": { |
| 31 | "@babel/core": "^7.6.2", | 32 | "@babel/core": "^7.6.2", |
| @@ -7177,6 +7177,9 @@ rimraf@~2.2.6: | @@ -7177,6 +7177,9 @@ rimraf@~2.2.6: | ||
| 7177 | resolved "https://registry.npm.taobao.org/rimraf/download/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582" | 7177 | resolved "https://registry.npm.taobao.org/rimraf/download/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582" |
| 7178 | integrity sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI= | 7178 | integrity sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI= |
| 7179 | 7179 | ||
| 7180 | +"rn-wechat@file:../rn-wechat": | ||
| 7181 | + version "0.0.2" | ||
| 7182 | + | ||
| 7180 | rsvp@^4.8.4: | 7183 | rsvp@^4.8.4: |
| 7181 | version "4.8.5" | 7184 | version "4.8.5" |
| 7182 | resolved "https://registry.npm.taobao.org/rsvp/download/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734" | 7185 | resolved "https://registry.npm.taobao.org/rsvp/download/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734" |
-
Please register or login to post a comment