質問編集履歴
3
connectでStackNavigationを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,10 @@
|
|
30
30
|
|
31
31
|
import { Card } from './common';
|
32
32
|
|
33
|
+
import { connect } from 'react-redux';
|
34
|
+
|
35
|
+
import { StackNavigator } from 'react-navigation';
|
36
|
+
|
33
37
|
|
34
38
|
|
35
39
|
class LibraryItem extends React.Component {
|
@@ -60,7 +64,7 @@
|
|
60
64
|
|
61
65
|
|
62
66
|
|
63
|
-
export default LibraryItem;
|
67
|
+
export default connect(StackNavigator)(LibraryItem);
|
64
68
|
|
65
69
|
```
|
66
70
|
|
2
consoleログの結果
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,6 +40,8 @@
|
|
40
40
|
|
41
41
|
const { naviate } = this.props.navigation;
|
42
42
|
|
43
|
+
console.log(this.props);
|
44
|
+
|
43
45
|
|
44
46
|
|
45
47
|
return (
|
@@ -64,6 +66,16 @@
|
|
64
66
|
|
65
67
|
|
66
68
|
|
69
|
+
consoleログの結果
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
Running application "library" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
|
67
79
|
> ./components/LibraryList.js(リスト)
|
68
80
|
|
69
81
|
|
1
修正点を更新しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
い
|
1
|
+
React Nativeの画面遷移でReact Navigationを導入したいと考えています。
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
|
5
|
-
|
3
|
+
イメージとしては、ホームにいくつかサムネイルが並んでいて、これをクリックすると詳細画面に遷移するというのが実現したい内容です。
|
4
|
+
|
5
|
+
|
6
|
+
|
6
|
-
|
7
|
+
## エラー
|
8
|
+
|
7
|
-
|
9
|
+
```
|
8
|
-
|
10
|
+
|
9
|
-
|
11
|
+
TypeError: Cannot read property 'navigate' of undefined
|
12
|
+
|
10
|
-
|
13
|
+
```
|
11
|
-
|
12
|
-
|
14
|
+
|
13
|
-
|
15
|
+
this.props.navigationが渡ってきていないようなのですが、その渡し方がいまいちわかっていません。
|
14
|
-
|
16
|
+
|
17
|
+
|
18
|
+
|
15
|
-
|
19
|
+
## ソースコード
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
|
19
|
-
> ./components/
|
21
|
+
> ./components/LibrarItem.js(サムネイル)
|
20
22
|
|
21
23
|
|
22
24
|
|
@@ -32,99 +34,101 @@
|
|
32
34
|
|
33
35
|
class LibraryItem extends React.Component {
|
34
36
|
|
37
|
+
|
38
|
+
|
39
|
+
const { title, description } = this.props.library;
|
40
|
+
|
41
|
+
const { naviate } = this.props.navigation;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
return (
|
46
|
+
|
47
|
+
<Card onPress={() => navigate('Detail', library)}>
|
48
|
+
|
49
|
+
<Text>{title}</Text>
|
50
|
+
|
51
|
+
</Card>
|
52
|
+
|
53
|
+
);
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
export default LibraryItem;
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
> ./components/LibraryList.js(リスト)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```JavaScript
|
72
|
+
|
73
|
+
import React from 'react';
|
74
|
+
|
75
|
+
import { ListView } from 'react-native';
|
76
|
+
|
77
|
+
import { connect } from 'react-redux';
|
78
|
+
|
79
|
+
import LibraryItem from './LibraryItem';
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
class LibraryList extends React.Component {
|
84
|
+
|
85
|
+
componentWillMount() {
|
86
|
+
|
87
|
+
const ds = new ListView.DataSource({
|
88
|
+
|
89
|
+
rowHasChanged: (r1, r2) => r1 !== r2
|
90
|
+
|
91
|
+
});
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
this.dataSource = ds.cloneWithRows(this.props.libraries);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
renderRow(library) {
|
102
|
+
|
103
|
+
return <LibraryItem library={library} />;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
35
109
|
render() {
|
36
110
|
|
37
|
-
const { id, title } = this.props.library;
|
38
|
-
|
39
|
-
|
40
|
-
|
41
111
|
return (
|
42
112
|
|
43
|
-
|
113
|
+
<ListView
|
44
|
-
|
45
|
-
|
114
|
+
|
46
|
-
|
47
|
-
>
|
48
|
-
|
49
|
-
|
115
|
+
dataSource={this.dataSource}
|
116
|
+
|
50
|
-
|
117
|
+
renderRow={this.renderRow}
|
118
|
+
|
51
|
-
|
119
|
+
/>
|
52
|
-
|
120
|
+
|
53
|
-
|
121
|
+
);
|
54
|
-
|
122
|
+
|
55
|
-
|
123
|
+
}
|
56
124
|
|
57
125
|
}
|
58
126
|
|
59
127
|
|
60
128
|
|
61
|
-
export default LibraryItem;
|
62
|
-
|
63
|
-
```
|
64
|
-
|
65
|
-
> ./components/LibraryList.js
|
66
|
-
|
67
|
-
```JavaScript
|
68
|
-
|
69
|
-
import React from 'react';
|
70
|
-
|
71
|
-
import { ListView } from 'react-native';
|
72
|
-
|
73
|
-
import { connect } from 'react-redux';
|
74
|
-
|
75
|
-
import LibraryItem from './LibraryItem';
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
class LibraruList extends React.Component {
|
80
|
-
|
81
|
-
componentWillMount() {
|
82
|
-
|
83
|
-
const ds = new ListView.DataSource({
|
84
|
-
|
85
|
-
rowHasChanged: (r1, r2) => r1 !== r2
|
86
|
-
|
87
|
-
});
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
this.dataSource = ds.cloneWithRows(this.props.libraries);
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
renderRow(library) {
|
98
|
-
|
99
|
-
return <LibraryItem library={library} />;
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
render() {
|
106
|
-
|
107
|
-
return (
|
108
|
-
|
109
|
-
<ListView
|
110
|
-
|
111
|
-
dataSource={this.dataSource}
|
112
|
-
|
113
|
-
renderRow={this.renderRow}
|
114
|
-
|
115
|
-
/>
|
116
|
-
|
117
|
-
);
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
129
|
const mapStateToProps = state => {
|
126
130
|
|
127
|
-
return { libraris: state.libraris };
|
131
|
+
return { libraries: state.libraries };
|
128
132
|
|
129
133
|
};
|
130
134
|
|
@@ -132,13 +136,9 @@
|
|
132
136
|
|
133
137
|
export default connect(mapStateToProps)(LibraryList);
|
134
138
|
|
135
|
-
|
136
|
-
|
137
|
-
```
|
139
|
+
```
|
138
|
-
|
139
|
-
|
140
|
-
|
140
|
+
|
141
|
-
> ./screens/ListScreen
|
141
|
+
> ./screens/ListScreen.js(スクリーン)
|
142
142
|
|
143
143
|
|
144
144
|
|
@@ -168,126 +168,50 @@
|
|
168
168
|
|
169
169
|
|
170
170
|
|
171
|
+
export default ListScreen;
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
> ./Router.js(ルーター)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
```JavaScript
|
182
|
+
|
183
|
+
import React from 'react';
|
184
|
+
|
185
|
+
import { StackNavigator } from 'react-navigation';
|
186
|
+
|
171
|
-
ListScreen.n
|
187
|
+
import { ListScreen } from './screens';
|
188
|
+
|
172
|
-
|
189
|
+
import { DetailScreen } from './screens';
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
export default StackNavigator({
|
194
|
+
|
195
|
+
List: {
|
196
|
+
|
197
|
+
screen: ListScreen
|
198
|
+
|
199
|
+
},
|
200
|
+
|
201
|
+
Detail: {
|
202
|
+
|
203
|
+
screen: DetailScreen
|
204
|
+
|
205
|
+
},
|
206
|
+
|
207
|
+
},{
|
208
|
+
|
173
|
-
tit
|
209
|
+
initialRouteName: 'List',
|
174
210
|
|
175
211
|
});
|
176
212
|
|
177
|
-
|
178
|
-
|
179
|
-
export default ListScreen;
|
180
|
-
|
181
|
-
```
|
213
|
+
```
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
214
|
+
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
215
|
+
|
190
|
-
|
191
|
-
|
216
|
+
|
192
|
-
|
193
|
-
import { View, Text } from 'react-native';
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
const DetailScreen = ({ navigation }) => {
|
198
|
-
|
199
|
-
return (
|
200
|
-
|
201
|
-
<View>
|
202
|
-
|
203
|
-
<Text>{library.description}</Text>
|
204
|
-
|
205
|
-
</View>
|
206
|
-
|
207
|
-
);
|
208
|
-
|
209
|
-
};
|
210
|
-
|
211
|
-
DetailScreen.navigationOptions = {
|
212
|
-
|
213
|
-
title: 'Detail',
|
214
|
-
|
215
|
-
};
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
export default DetailScreen;
|
220
|
-
|
221
|
-
```
|
222
|
-
|
223
|
-
> ./Router.js
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
```JavaScript
|
228
|
-
|
229
|
-
import React from 'react';
|
230
|
-
|
231
|
-
import { StackNavigator } from 'react-navigation';
|
232
|
-
|
233
|
-
import { ListScreen } from './screens';
|
234
|
-
|
235
|
-
import { DetailScreen } from './screens';
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
export default StackNavigator({
|
240
|
-
|
241
|
-
List: { screen: ListScreen },
|
242
|
-
|
243
|
-
Detail: { screen: DetailScreen },
|
244
|
-
|
245
|
-
},{
|
246
|
-
|
247
|
-
initialRouteName: 'List',
|
248
|
-
|
249
|
-
});
|
250
|
-
|
251
|
-
```
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
> ./reducers/LibraryReducer.js
|
256
|
-
|
257
|
-
```JavaScript
|
258
|
-
|
259
|
-
import data from './LibraryList.json'
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
export default () => data;
|
264
|
-
|
265
|
-
```
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
> ./reducers/LibraryList.json
|
270
|
-
|
271
|
-
```
|
272
|
-
|
273
|
-
[
|
274
|
-
|
275
|
-
{
|
276
|
-
|
277
|
-
"id": 0,
|
278
|
-
|
279
|
-
"title": "react native",
|
280
|
-
|
281
|
-
"description": "zzzzzzzzzzzzzzz"
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
]
|
286
|
-
|
287
|
-
```
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
ホーム表示はできているのですが、その先にいけません。。。
|
292
|
-
|
293
|
-
どうぞ
|
217
|
+
すみませんが、どうぞよろしくお願いします。
|