質問編集履歴

5

被っていたコードを消しました

2018/02/06 00:37

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -232,78 +232,24 @@
232
232
 
233
233
 
234
234
 
235
- > Router.js
235
+ > App.js
236
236
 
237
237
 
238
238
 
239
239
  ```JavaScript
240
240
 
241
+ /**
242
+
243
+ * Sample React Native App
244
+
245
+ * https://github.com/facebook/react-native
246
+
247
+ * @flow
248
+
249
+ */
250
+
241
251
  import React from 'react';
242
252
 
243
- import { StackNavigator } from 'react-navigation';
244
-
245
- import { SignInScreen, HomeScreen } from './screens';
246
-
247
-
248
-
249
- const Router = StackNavigator({
250
-
251
- SignIn: {
252
-
253
- screen: SignInScreen,
254
-
255
- navigationOptions: {
256
-
257
- title: 'SignIn',
258
-
259
- }
260
-
261
- },
262
-
263
- Main: {
264
-
265
- screen: HomeScreen,
266
-
267
- navigationOptions: {
268
-
269
- title: 'Home',
270
-
271
- }
272
-
273
- },
274
-
275
- }, {
276
-
277
- initialRouteName: 'SignIn'
278
-
279
- });
280
-
281
-
282
-
283
- export default Router;
284
-
285
- ```
286
-
287
-
288
-
289
- > App.js
290
-
291
-
292
-
293
- ```JavaScript
294
-
295
- /**
296
-
297
- * Sample React Native App
298
-
299
- * https://github.com/facebook/react-native
300
-
301
- * @flow
302
-
303
- */
304
-
305
- import React from 'react';
306
-
307
253
  import { createStore, applyMiddleware } from 'redux';
308
254
 
309
255
  import ReduxThunk from 'redux-thunk';

4

App.js、Router.js、呼び起こしている部分を追記しました

2018/02/06 00:37

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -10,9 +10,11 @@
10
10
 
11
11
  ```JavaScript
12
12
 
13
- / Calling the following function will open the FB login dialogue:
13
+ // Calling the following function will open the FB login dialogue:
14
-
14
+
15
- const Auth = (props) => {
15
+ const Auth = () => {
16
+
17
+
16
18
 
17
19
  return LoginManager
18
20
 
@@ -20,6 +22,8 @@
20
22
 
21
23
  .then((result) => {
22
24
 
25
+
26
+
23
27
  if (!result.isCancelled) {
24
28
 
25
29
  console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`)
@@ -54,30 +58,58 @@
54
58
 
55
59
  console.log(currentUser);
56
60
 
61
+ return this.props.navigation.navigate('Main');
62
+
63
+ }
64
+
65
+ })
66
+
67
+ .catch((error) => {
68
+
69
+ console.log(`Login fail with error: ${error}`)
70
+
71
+ })
72
+
73
+ }
74
+
75
+
76
+
77
+ class SignInScreen extends React.Component {
78
+
79
+ render() {
80
+
81
+ const { navigate } = this.props.navigation;
82
+
83
+
84
+
85
+ return (
86
+
87
+ <View style={styles.containerStyle}>
88
+
89
+ <TouchableOpacity onPress={Auth}>
90
+
91
+ <Text style={styles.textStyle}>Facebook</Text>
92
+
93
+ </TouchableOpacity>
94
+
95
+ </View>
96
+
97
+ );
98
+
99
+ }
100
+
101
+ }
102
+
103
+ ```
104
+
105
+
106
+
107
+ 上記の(currentUser)後に
108
+
109
+ ```
110
+
57
111
  this.props.navigation.navigate('Main');
58
112
 
59
- }
60
-
61
- })
62
-
63
- .catch((error) => {
64
-
65
- console.log(`Login fail with error: ${error}`)
66
-
67
- })
68
-
69
- }
70
-
71
- ```
72
-
73
-
74
-
75
- 上記の(currentUser)後に
76
-
77
- ```
78
-
79
- this.props.navigation.navigate('Main');
80
-
81
113
  ```
82
114
 
83
115
  してみたのですが、Mainの画面へ遷移しません。。(特にエラーコードもなし)
@@ -196,4 +228,128 @@
196
228
 
197
229
 
198
230
 
231
+ ### 追記(3)
232
+
233
+
234
+
235
+ > Router.js
236
+
237
+
238
+
239
+ ```JavaScript
240
+
241
+ import React from 'react';
242
+
243
+ import { StackNavigator } from 'react-navigation';
244
+
245
+ import { SignInScreen, HomeScreen } from './screens';
246
+
247
+
248
+
249
+ const Router = StackNavigator({
250
+
251
+ SignIn: {
252
+
253
+ screen: SignInScreen,
254
+
255
+ navigationOptions: {
256
+
257
+ title: 'SignIn',
258
+
259
+ }
260
+
261
+ },
262
+
263
+ Main: {
264
+
265
+ screen: HomeScreen,
266
+
267
+ navigationOptions: {
268
+
269
+ title: 'Home',
270
+
271
+ }
272
+
273
+ },
274
+
275
+ }, {
276
+
277
+ initialRouteName: 'SignIn'
278
+
279
+ });
280
+
281
+
282
+
283
+ export default Router;
284
+
285
+ ```
286
+
287
+
288
+
289
+ > App.js
290
+
291
+
292
+
293
+ ```JavaScript
294
+
295
+ /**
296
+
297
+ * Sample React Native App
298
+
299
+ * https://github.com/facebook/react-native
300
+
301
+ * @flow
302
+
303
+ */
304
+
305
+ import React from 'react';
306
+
307
+ import { createStore, applyMiddleware } from 'redux';
308
+
309
+ import ReduxThunk from 'redux-thunk';
310
+
311
+ import { Provider } from 'react-redux';
312
+
313
+ import { View } from 'react-native';
314
+
315
+ import Reducers from './reducers';
316
+
317
+ import Router from './Router';
318
+
319
+
320
+
321
+ const App = () => {
322
+
323
+
324
+
325
+ const store = createStore(Reducers, {}, applyMiddleware(ReduxThunk));
326
+
327
+
328
+
329
+ return (
330
+
331
+ <Provider store={store}>
332
+
333
+ <View style={{ flex: 1 }}>
334
+
335
+ <Router />
336
+
337
+ </View>
338
+
339
+ </Provider>
340
+
341
+ );
342
+
343
+ };
344
+
345
+
346
+
347
+ export default App;
348
+
349
+ ```
350
+
351
+
352
+
353
+
354
+
199
355
  こちらでやってもできません。。

3

navigationを追加しました

2018/02/06 00:36

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -144,6 +144,10 @@
144
144
 
145
145
 
146
146
 
147
+ ### 追記(1)
148
+
149
+
150
+
147
151
  console.logで this.props.navigation の中身を見てみたのですが、
148
152
 
149
153
 
@@ -171,3 +175,25 @@
171
175
  ```
172
176
 
173
177
  を追加したのですが、今度はnavigationエラーとなってしまいました(汗
178
+
179
+
180
+
181
+ ### 追記(2)
182
+
183
+
184
+
185
+ ```JavaScript
186
+
187
+ class SignInScreen extends React.Component {
188
+
189
+ render() {
190
+
191
+ const { navigation } = this.props;
192
+
193
+ ・・・
194
+
195
+ ```
196
+
197
+
198
+
199
+ こちらでやってもできません。。

2

consolelogをみてみました

2018/02/05 09:24

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -141,3 +141,33 @@
141
141
  お知恵を拝借できれば幸いです(_ _)
142
142
 
143
143
  Facebookの認証自体は成功するのですが、その後の遷移がうまく行きません。
144
+
145
+
146
+
147
+ console.logで this.props.navigation の中身を見てみたのですが、
148
+
149
+
150
+
151
+ ```
152
+
153
+ Login fail with error: TypeError: Cannot read property 'navigate' of undefined
154
+
155
+ ```
156
+
157
+ と出たので、
158
+
159
+ ```
160
+
161
+ const Auth = () => {
162
+
163
+ const { navigation } = this.props;
164
+
165
+
166
+
167
+ return LoginManager
168
+
169
+ ・・・
170
+
171
+ ```
172
+
173
+ を追加したのですが、今度はnavigationエラーとなってしまいました(汗

1

追記

2018/02/05 08:46

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -139,3 +139,5 @@
139
139
 
140
140
 
141
141
  お知恵を拝借できれば幸いです(_ _)
142
+
143
+ Facebookの認証自体は成功するのですが、その後の遷移がうまく行きません。