diff --git a/example/ThreadExample/.babelrc b/example/SimpleExample/.babelrc similarity index 100% rename from example/ThreadExample/.babelrc rename to example/SimpleExample/.babelrc diff --git a/example/ThreadExample/.buckconfig b/example/SimpleExample/.buckconfig similarity index 100% rename from example/ThreadExample/.buckconfig rename to example/SimpleExample/.buckconfig diff --git a/example/ThreadExample/.flowconfig b/example/SimpleExample/.flowconfig similarity index 76% rename from example/ThreadExample/.flowconfig rename to example/SimpleExample/.flowconfig index 83461209da0695bff403b2cf3f87690f50362e91..a359500eea1204965d0be17c722b269a169e0fe4 100644 --- a/example/ThreadExample/.flowconfig +++ b/example/SimpleExample/.flowconfig @@ -12,14 +12,15 @@ ; For RN Apps installed via npm, "Libraries" folder is inside ; "node_modules/react-native" but in the source repo it is in the root .*/Libraries/react-native/React.js -.*/Libraries/react-native/ReactNative.js + +; Ignore polyfills +.*/Libraries/polyfills/.* [include] [libs] node_modules/react-native/Libraries/react-native/react-native-interface.js -node_modules/react-native/flow -flow/ +node_modules/react-native/flow/ [options] emoji=true @@ -32,14 +33,16 @@ module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|we suppress_type=$FlowIssue suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState suppress_type=$FixMe -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-3]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-3]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError unsafe.enable_getters_and_setters=true [version] -^0.49.1 +^0.53.0 diff --git a/example/ThreadExample/.gitattributes b/example/SimpleExample/.gitattributes similarity index 100% rename from example/ThreadExample/.gitattributes rename to example/SimpleExample/.gitattributes diff --git a/example/ThreadExample/.gitignore b/example/SimpleExample/.gitignore similarity index 81% rename from example/ThreadExample/.gitignore rename to example/SimpleExample/.gitignore index 10be19751febde9c1707b56b038b4bd85f5597b9..0826423b786cca300853d76522d890cbba599cfc 100644 --- a/example/ThreadExample/.gitignore +++ b/example/SimpleExample/.gitignore @@ -46,8 +46,8 @@ buck-out/ # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the # screenshots whenever they are needed. # For more information about the recommended setup visit: -# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md +# https://docs.fastlane.tools/best-practices/source-control/ -fastlane/report.xml -fastlane/Preview.html -fastlane/screenshots +*/fastlane/report.xml +*/fastlane/Preview.html +*/fastlane/screenshots diff --git a/example/ThreadExample/.watchmanconfig b/example/SimpleExample/.watchmanconfig similarity index 100% rename from example/ThreadExample/.watchmanconfig rename to example/SimpleExample/.watchmanconfig diff --git a/example/SimpleExample/App.js b/example/SimpleExample/App.js new file mode 100644 index 0000000000000000000000000000000000000000..1fdb36452e06db7673005d28f96f0665fb4fc6c5 --- /dev/null +++ b/example/SimpleExample/App.js @@ -0,0 +1,65 @@ +import React, { Component } from 'react'; +import { + Button, + StyleSheet, + Text, + View +} from 'react-native'; +import { Thread } from 'react-native-threads'; + +export default class App extends Component<{}> { + state = { messages: [] } + + workerThread = null; + + componentDidMount() { + this.workerThread = new Thread('./worker.thread.js'); + this.workerThread.onmessage = this.handleMessage; + } + + componentWillUnmount() { + this.workerThread.terminate(); + this.workerThread = null; + } + + handleMessage = message => { + console.tron.log(`APP: got message ${message}`); + + this.setState(state => { + return { messages: [...state.messages, message] }; + }); + } + + render() { + return ( + + + Welcome to React Native Threads! + + +