Skip to content

Commit e103961

Browse files
react-native: update samples react-native to 0.52
Updates the react-native version of the SuspendResume sample to 0.52.0. Corrects a Warning message on Android due to trying to update an unmounted component by removing the listener when unmounting.
1 parent eb3451e commit e103961

File tree

15 files changed

+7667
-128
lines changed

15 files changed

+7667
-128
lines changed

react-native/SuspendResume/.flowconfig

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
; For RN Apps installed via npm, "Libraries" folder is inside
1313
; "node_modules/react-native" but in the source repo it is in the root
1414
.*/Libraries/react-native/React.js
15-
.*/Libraries/react-native/ReactNative.js
15+
16+
; Ignore polyfills
17+
.*/Libraries/polyfills/.*
18+
19+
; Ignore metro
20+
.*/node_modules/metro/.*
1621

1722
[include]
1823

1924
[libs]
2025
node_modules/react-native/Libraries/react-native/react-native-interface.js
21-
node_modules/react-native/flow
22-
flow/
26+
node_modules/react-native/flow/
27+
node_modules/react-native/flow-github/
2328

2429
[options]
2530
emoji=true
@@ -30,16 +35,22 @@ munge_underscores=true
3035

3136
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
3237

38+
module.file_ext=.js
39+
module.file_ext=.jsx
40+
module.file_ext=.json
41+
module.file_ext=.native.js
42+
3343
suppress_type=$FlowIssue
3444
suppress_type=$FlowFixMe
35-
suppress_type=$FixMe
45+
suppress_type=$FlowFixMeProps
46+
suppress_type=$FlowFixMeState
3647

37-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
38-
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]+
48+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
49+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
3950
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
4051
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
4152

4253
unsafe.enable_getters_and_setters=true
4354

4455
[version]
45-
^0.49.1
56+
^0.61.0

react-native/SuspendResume/.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ buck-out/
4646
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
4747
# screenshots whenever they are needed.
4848
# For more information about the recommended setup visit:
49-
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
49+
# https://docs.fastlane.tools/best-practices/source-control/
5050

51-
fastlane/report.xml
52-
fastlane/Preview.html
53-
fastlane/screenshots
51+
*/fastlane/report.xml
52+
*/fastlane/Preview.html
53+
*/fastlane/screenshots

react-native/SuspendResume/index.android.js renamed to react-native/SuspendResume/App.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import React, { Component } from 'react';
88
import {
9-
AppRegistry,
9+
Platform,
1010
StyleSheet,
1111
Text,
1212
Button,
@@ -16,22 +16,30 @@ import {
1616

1717
import nodejs from 'nodejs-mobile-react-native';
1818

19-
export default class SuspendResume extends Component {
19+
export default class App extends Component<{}> {
2020
constructor(props){
2121
super(props);
2222
this.state = { lastNodeMessage: "No message yet." };
23+
this.listenerRef = null;
2324
}
2425
componentWillMount()
2526
{
2627
nodejs.start('main.js');
28+
this.listenerRef = ((msg) => {
29+
this.setState({lastNodeMessage: msg});
30+
});
2731
nodejs.channel.addListener(
2832
"message",
29-
(msg) => {
30-
this.setState({lastNodeMessage: msg});
31-
},
33+
this.listenerRef,
3234
this
3335
);
3436
}
37+
componentWillUnmount()
38+
{
39+
if (this.listenerRef) {
40+
nodejs.channel.removeListener("message", this.listenerRef);
41+
}
42+
}
3543
componentDidMount(){
3644
AppState.addEventListener('change', (state) => {
3745
if (state === 'active') {
@@ -74,5 +82,3 @@ const styles = StyleSheet.create({
7482
marginBottom: 5,
7583
},
7684
});
77-
78-
AppRegistry.registerComponent('SuspendResume', () => SuspendResume);

react-native/SuspendResume/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,35 @@ rn_bridge.channel.send("Node was initialized.");
9898

9999
The React Native interface takes care of querying `Node.js` for versions and showing it in the UI. It also signals when the App enters the background and comes back again, through `AppState`.
100100

101-
index.ios.js and index.android.js contents:
101+
App.js contents:
102102
```js
103103
...
104104
import nodejs from 'nodejs-mobile-react-native';
105105

106-
export default class SuspendResume extends Component {
106+
export default class App extends Component<{}> {
107107
constructor(props){
108108
super(props);
109109
this.state = { lastNodeMessage: "No message yet." };
110+
this.listenerRef = null;
110111
}
111112
componentWillMount()
112113
{
113114
nodejs.start('main.js');
115+
this.listenerRef = ((msg) => {
116+
this.setState({lastNodeMessage: msg});
117+
});
114118
nodejs.channel.addListener(
115119
"message",
116-
(msg) => {
117-
this.setState({lastNodeMessage: msg});
118-
},
120+
this.listenerRef,
119121
this
120122
);
121123
}
124+
componentWillUnmount()
125+
{
126+
if (this.listenerRef) {
127+
nodejs.channel.removeListener("message", this.listenerRef);
128+
}
129+
}
122130
componentDidMount(){
123131
AppState.addEventListener('change', (state) => {
124132
if (state === 'active') {
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import 'react-native';
22
import React from 'react';
3-
import Index from '../index.ios.js';
3+
import App from '../App';
44

55
// Note: test renderer must be required after react-native.
66
import renderer from 'react-test-renderer';
77

88
it('renders correctly', () => {
99
const tree = renderer.create(
10-
<Index />
10+
<App />
1111
);
1212
});

react-native/SuspendResume/__tests__/index.android.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

react-native/SuspendResume/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ import com.android.build.OutputFile
7272
* ]
7373
*/
7474

75+
project.ext.react = [
76+
entryFile: "index.js"
77+
]
78+
7579
apply from: "../../node_modules/react-native/react.gradle"
7680

7781
/**

react-native/SuspendResume/android/app/src/main/java/com/suspendresume/MainApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ protected List<ReactPackage> getPackages() {
2525
new MainReactPackage()
2626
);
2727
}
28+
29+
@Override
30+
protected String getJSMainModuleName() {
31+
return "index";
32+
}
2833
};
2934

3035
@Override

react-native/SuspendResume/index.ios.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

react-native/SuspendResume/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { AppRegistry } from 'react-native';
2+
import App from './App';
3+
4+
AppRegistry.registerComponent('SuspendResume', () => App);

0 commit comments

Comments
 (0)