diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7c28613 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +# Windows files +[*.bat] +end_of_line = crlf diff --git a/.flowconfig b/.flowconfig index 786366c..7c3a4c6 100644 --- a/.flowconfig +++ b/.flowconfig @@ -8,10 +8,6 @@ ; Ignore polyfills node_modules/react-native/Libraries/polyfills/.* -; These should not be required directly -; require from fbjs/lib instead: require('fbjs/lib/warning') -node_modules/warning/.* - ; Flow doesn't support platforms .*/Libraries/Utilities/LoadingView.js @@ -27,8 +23,7 @@ node_modules/react-native/flow/ [options] emoji=true -esproposal.optional_chaining=enable -esproposal.nullish_coalescing=enable +exact_by_default=true module.file_ext=.js module.file_ext=.json @@ -44,10 +39,6 @@ suppress_type=$FlowFixMe suppress_type=$FlowFixMeProps suppress_type=$FlowFixMeState -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ -suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError - [lints] sketchy-null-number=warn sketchy-null-mixed=warn @@ -56,10 +47,8 @@ untyped-type-import=warn nonstrict-import=warn deprecated-type=warn unsafe-getters-setters=warn -inexact-spread=warn unnecessary-invariant=warn signature-verification-failure=warn -deprecated-utility=error [strict] deprecated-type @@ -71,4 +60,4 @@ untyped-import untyped-type-import [version] -^0.113.0 +^0.149.0 diff --git a/.gitattributes b/.gitattributes index d42ff18..45a3dcb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ -*.pbxproj -text +# Windows files should use crlf line endings +# https://help.github.com/articles/dealing-with-line-endings/ +*.bat text eol=crlf diff --git a/.github/workflows/issue.yml b/.github/workflows/issue.yml new file mode 100644 index 0000000..8a4587e --- /dev/null +++ b/.github/workflows/issue.yml @@ -0,0 +1,13 @@ +name: Notify +on: + issues: + types: [opened] + issue_comment: + types: [created] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Notify + run: curl --location --request POST 'https://api.finogeeks.club/api/v1/finstore/webhooks/61b331d79b3dad0001f72fa2/postreceive?nonce=jhd2QyrArsc' --header "Content-Type:application/json" --data-raw '{"msg":"仓库 ${{github.repository}} 有新的 issue"}' diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..b5872ff --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,11 @@ +name: Notify +on: + pull_request: + branches: [ master ] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Notify + run: curl --location --request POST 'https://api.finogeeks.club/api/v1/finstore/webhooks/61b331d79b3dad0001f72fa2/postreceive?nonce=jhd2QyrArsc' --header "Content-Type:application/json" --data-raw '{"msg":"仓库 ${{github.repository}} 有新的 PR ${{ github.event.pull_request._links.html.href }}"}' diff --git a/.prettierrc.js b/.prettierrc.js index 5c4de1a..84196d9 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -3,4 +3,5 @@ module.exports = { jsxBracketSameLine: true, singleQuote: true, trailingComma: 'all', + arrowParens: 'avoid', }; diff --git a/App.js b/App.js index 4c46d40..6945f33 100644 --- a/App.js +++ b/App.js @@ -1,93 +1,348 @@ /** * Sample React Native App - * - * adapted from App.js generated by the following command: - * - * react-native init example - * * https://github.com/facebook/react-native + * + * @format + * @flow strict-local */ -import React, { Component } from 'react'; -import { Platform, StyleSheet, Text, View, Button } from 'react-native'; +import React, {useState, useEffect} from 'react'; +import type {Node} from 'react'; +import BackgroundTimer from 'react-native-background-timer'; + +const appId = '6260bf62e680b10001b1911f'; import MopSDK from 'react-native-mopsdk'; -const onPressOpenCanvasApplet = () => { - MopSDK.openApplet('5ea03fa563cb900001d73863', '', '', (data) => { }); +import { + SafeAreaView, + ScrollView, + StatusBar, + StyleSheet, + Text, + useColorScheme, + Button, + View, + Platform, + NativeModules, + Alert, + NativeEventEmitter, +} from 'react-native'; + +import ScanScreen from './scanner.js'; + +let isInited = false; + +const openApplet = () => { + MopSDK.openApplet({appId}); +}; + +const getCurrentApplet = callback => { + let time = 0; + BackgroundTimer.runBackgroundTimer(() => { + if (time === 0) { + console.log('getCurrentApplet call'); + MopSDK.currentApplet().then(res => { + console.log('currentApplet', res); + callback(JSON.stringify(res)); + }); + time++; + } + }, 10000); +}; + +const closeApplet = () => { + let time = 0; + BackgroundTimer.runBackgroundTimer(() => { + if (time === 0) { + console.log('closeApplet call'); + MopSDK.closeApplet(appId, true); + time++; + } + }, 10000); +}; + +const closeAllApplets = () => { + let time = 0; + BackgroundTimer.runBackgroundTimer(() => { + if (time === 0) { + Alert.alert('closeAllApplets call'); + MopSDK.closeAllApplets(); + time++; + } + }, 10000); }; -const onPressOpenDemoApplet = () => { - MopSDK.openApplet('5ea0401463cb900001d73865', '', '', (data) => { }); + +const qrcodeOpenApplet = qrcode => { + console.warn('当前扫码', qrcode); + + console.log('qrcodeOpenApplet call'); + MopSDK.qrcodeOpenApplet(qrcode); }; -const onPressOpenProfileApplet = () => { - MopSDK.openApplet('5ea0412663cb900001d73867', '', '', (data) => { }); + +const clearApplets = () => { + console.log('clearApplets call'); + MopSDK.clearApplets(); }; -export default class App extends Component<{}> { - state = { - status: 'starting', - message: '--', + +const registerAppletHandler = () => { + const handler = { + forwardApplet(params) { + console.log('forwardApplet call', params); + return []; + }, + getUserInfo(params) { + console.log('getUserInfo call', params); + return { + name: 'jimmy', + nickName: 'jimmy 123', + avatarUrl: + 'https://img9.doubanio.com/view/subject/s/public/s34197964.jpg', + }; + }, + getCustomMenus(params) { + console.log('getCustomMenus call'); + let list = [ + { + menuId: 'menuid1', + image: 'image', + title: 'title', + type: 'type', + foo: 'foo', + }, + { + menuId: 'menuid2', + image: 'image', + title: 'title', + type: 'type', + foo: 'foo', + }, + { + menuId: 'menuid2', + image: 'image', + title: 'title', + type: 'type', + foo: 'foo', + }, + { + menuId: 'menuid4', + image: 'image', + title: 'title', + type: 'type', + foo: 'foo', + }, + ]; + return list; + }, + onCustomMenuClick(params) { + console.log('onCustomMenuClick', params); + }, + appletDidOpen(params) { + console.log('appletDidOpen', params); + return params; + }, }; - componentDidMount() { - MopSDK.initialize( - { - appkey: '22LyZEib0gLTQdU3MUauASlb4KFRNRajt4RmY6UDSucA', - secret: 'c5cc7a8c14a2b04a', - apiServer: 'https://mp.finogeeks.com', - apiPrefix: '/api/v1/mop', - }, - (data) => { - console.log('message;', data); - const s = JSON.stringify(data); - this.setState({ - status: 'native callback received', - message: s, - }); - }, - ); + MopSDK.registerAppletHandler(handler); +}; + +const addWebExtentionApi = () => { + console.log('addWebExtentionApi call'); + const rnWebCustomAPI = params => { + console.warn('webview 自定义api rnWebCustomAPI call', params); + return { + errMsg: 'rnWebCustomAPI:ok', + data: 'customAPI', + }; + }; + MopSDK.addWebExtentionApi('rnWebCustomAPI', rnWebCustomAPI); +}; + +const registerExtensionApi = () => { + console.log('registerExtensionApi call'); + const rnCustomAPI = params => { + console.warn('自定义 api rn rnCustomAPI call', params); + return { + errMsg: 'rnCustomAPI:ok', + data: 'webCustomAPI', + }; + }; + MopSDK.registerExtensionApi('rnCustomAPI', rnCustomAPI); +}; + +const callJS = () => { + if (Platform.OS !== 'android') { + let time = 0; + BackgroundTimer.runBackgroundTimer(() => { + if (time === 0) { + console.warn('ios calljs 执行'); + MopSDK.callJS(appId, 'app2jsFunction', { + data: 100, + }) + .then(res => { + Alert.alert('calljs 调用成功'); + console.warn('calljs 调用成功', res); + }) + .catch(res => { + Alert.alert('calljs 失败'); + console.warn('calljs 调用失败', res); + }); + time++; + } + }, 10000); + } else { + MopSDK.callJS(appId, 'app2jsFunction', { + data: 100, + }) + .then(res => { + console.warn('calljs 调用成功', res); + }) + .catch(res => { + console.warn('calljs 调用失败', res); + }); } - render() { - return ( - - ☆FINMopsdk example☆ - STATUS: {this.state.status} - ☆NATIVE CALLBACK MESSAGE☆ - {this.state.message} -