Selaa lähdekoodia

fixed reload bug

Daniel Zlotin 8 vuotta sitten
vanhempi
commit
f56c6b4d0e

+ 9
- 0
ios/RNN.m Näytä tiedosto

@@ -30,6 +30,10 @@
30 30
 -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions
31 31
 {
32 32
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptLoaded) name:RCTJavaScriptDidLoadNotification object:nil];
33
+#pragma GCC diagnostic push
34
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
35
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptDevReload) name:RCTReloadNotification object:nil];
36
+#pragma GCC diagnostic pop
33 37
     // this will load the JS bundle
34 38
     bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions];
35 39
 }
@@ -39,6 +43,11 @@
39 43
     [RNNEventEmitter sendOnAppLaunched];
40 44
 }
41 45
 
46
+-(void)onJavaScriptDevReload
47
+{
48
+    UIApplication.sharedApplication.delegate.window.rootViewController = nil;
49
+}
50
+
42 51
 -(RCTBridge *)bridge
43 52
 {
44 53
     return bridge;

+ 2
- 27
playground/src/app.js Näytä tiedosto

@@ -1,35 +1,10 @@
1
-import React, {Component} from 'react';
2
-import {View, Text} from 'react-native';
3
-
4 1
 import Navigation from 'react-native-navigation';
5 2
 
6
-const styles = {
7
-  root: {
8
-    flexGrow: 1,
9
-    justifyContent: 'center',
10
-    alignItems: 'center',
11
-    backgroundColor: '#f5fcff'
12
-  },
13
-  h1: {
14
-    fontSize: 24,
15
-    textAlign: 'center',
16
-    margin: 10
17
-  }
18
-};
19
-
20
-class WelcomeScreen extends Component {
21
-  render() {
22
-    return (
23
-      <View style={styles.root}>
24
-        <Text style={styles.h1}>{`React Native Navigation!`}</Text>
25
-      </View>
26
-    );
27
-  }
28
-}
3
+import {registerContainers} from './containers';
29 4
 
30 5
 export function start() {
6
+  registerContainers();
31 7
   Navigation.onAppLaunched(() => {
32
-    Navigation.registerContainer(`com.example.WelcomeScreen`, () => WelcomeScreen);
33 8
     Navigation.startApp({
34 9
       container: {
35 10
         name: 'com.example.WelcomeScreen'

+ 26
- 0
playground/src/containers/WelcomeScreen.js Näytä tiedosto

@@ -0,0 +1,26 @@
1
+import React, {Component} from 'react';
2
+import {View, Text} from 'react-native';
3
+
4
+export default class WelcomeScreen extends Component {
5
+  render() {
6
+    return (
7
+      <View style={styles.root}>
8
+        <Text style={styles.h1}>{`React Native Navigation!`}</Text>
9
+      </View>
10
+    );
11
+  }
12
+}
13
+
14
+const styles = {
15
+  root: {
16
+    flexGrow: 1,
17
+    justifyContent: 'center',
18
+    alignItems: 'center',
19
+    backgroundColor: '#f5fcff'
20
+  },
21
+  h1: {
22
+    fontSize: 24,
23
+    textAlign: 'center',
24
+    margin: 10
25
+  }
26
+};

+ 7
- 0
playground/src/containers/index.js Näytä tiedosto

@@ -0,0 +1,7 @@
1
+import Navigation from 'react-native-navigation';
2
+
3
+import WelcomeScreen from './WelcomeScreen';
4
+
5
+export function registerContainers() {
6
+  Navigation.registerContainer(`com.example.WelcomeScreen`, () => WelcomeScreen);
7
+}

+ 2
- 1
src/Navigation.js Näytä tiedosto

@@ -8,9 +8,10 @@ import Commands from './commands/Commands';
8 8
 
9 9
 class Navigation {
10 10
   constructor() {
11
+    this.store = new Store();
11 12
     this.nativeEventsReceiver = new NativeEventsReceiver();
12 13
     this.uniqueIdProvider = new UniqueIdProvider();
13
-    this.containerRegistry = new ContainerRegistry(new Store());
14
+    this.containerRegistry = new ContainerRegistry(this.store);
14 15
     this.commands = new Commands(new NativeCommandsSender(), this.uniqueIdProvider);
15 16
   }
16 17