質問編集履歴
4
質問内容を書き直しました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
AnimatedViewをfetchしたViewで表示したい(react native)
|
test
CHANGED
@@ -1,551 +1,717 @@
|
|
1
|
-
|
1
|
+
質問の内容に不備がありましたので、再度こちらにて訂正させて載せさせていただきます。
|
2
|
+
|
2
|
-
|
3
|
+
React Native Mapというライブラリで、Animated Viewを表示できるようにしたいと考えています。
|
3
|
-
|
4
|
-
|
4
|
+
|
5
|
+
|
6
|
+
|
5
|
-
|
7
|
+
[こちらのリンク先にあるAnimatedView.js](https://github.com/react-community/react-native-maps/blob/master/example/examples/AnimatedViews.js)をコピペするとちゃんと表示されるのですが、自前のデータベースからFetchしてきたデータを当てようとすると下記のエラーが生じてしまいます。
|
6
|
-
|
7
|
-
しかし、下記のエラーが生じてしまい表示できずじまいです。。
|
8
8
|
|
9
9
|
|
10
10
|
|
11
11
|
```
|
12
12
|
|
13
|
-
|
13
|
+
Invariant Violation: outputRange must have at least 2 elements
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
※[こちらのエラーをぐぐってみた](https://github.com/react-community/react-native-maps/issues/746)のですが、未解決のようです。。。
|
18
|
-
|
18
|
+
|
19
|
+
|
20
|
+
|
19
|
-
|
21
|
+
変更点は下記の部分です。
|
22
|
+
|
23
|
+
|
24
|
+
|
20
|
-
|
25
|
+
> Fetchするためのredux追加
|
26
|
+
|
27
|
+
|
28
|
+
|
21
|
-
|
29
|
+
```JavaScript
|
30
|
+
|
22
|
-
|
31
|
+
・・・
|
32
|
+
|
33
|
+
const mapStateToProps = (state) => {
|
34
|
+
|
35
|
+
const markers = _.orderBy(state.markers, ['id'], ['desc']);
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
return { markers };
|
40
|
+
|
41
|
+
};
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
export default connect(mapStateToProps, {
|
46
|
+
|
47
|
+
markersFetch
|
48
|
+
|
23
|
-
|
49
|
+
})(AnimatedViews);
|
24
|
-
|
25
|
-
|
26
50
|
|
27
51
|
```
|
28
52
|
|
53
|
+
|
54
|
+
|
55
|
+
> this.stateで出していたmarkersをthis.propsで書き換え
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```JavaScript
|
60
|
+
|
61
|
+
const {
|
62
|
+
|
63
|
+
・・・
|
64
|
+
|
65
|
+
markers
|
66
|
+
|
67
|
+
} = this.state;
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
上記の部分を下記のように書き換えました。
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```JavaScript
|
78
|
+
|
79
|
+
const { markers } = this.props;
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
どのようにして解決すればよろしいでしょうか・・・。
|
86
|
+
|
87
|
+
お手数ですが、おたすけくださいませ。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
▼ソースコードはこちらです
|
94
|
+
|
95
|
+
```JavaScript
|
96
|
+
|
97
|
+
・・・
|
98
|
+
|
99
|
+
|
100
|
+
|
29
101
|
function getMarkerState(panX, panY, scrollY, i) {
|
30
102
|
|
103
|
+
const xLeft = (-SNAP_WIDTH * i) + (SNAP_WIDTH / 2);
|
104
|
+
|
105
|
+
const xRight = (-SNAP_WIDTH * i) - (SNAP_WIDTH / 2);
|
106
|
+
|
107
|
+
const xPos = -SNAP_WIDTH * i;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
const isIndex = panX.interpolate({
|
112
|
+
|
113
|
+
inputRange: [xRight - 1, xRight, xLeft, xLeft + 1],
|
114
|
+
|
115
|
+
outputRange: [0, 1, 1, 0],
|
116
|
+
|
117
|
+
extrapolate: 'clamp',
|
118
|
+
|
119
|
+
});
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
const isNotIndex = panX.interpolate({
|
124
|
+
|
125
|
+
inputRange: [xRight - 1, xRight, xLeft, xLeft + 1],
|
126
|
+
|
127
|
+
outputRange: [1, 0, 0, 1],
|
128
|
+
|
129
|
+
extrapolate: 'clamp',
|
130
|
+
|
131
|
+
});
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
const center = panX.interpolate({
|
136
|
+
|
137
|
+
inputRange: [xPos - 10, xPos, xPos + 10],
|
138
|
+
|
139
|
+
outputRange: [0, 1, 0],
|
140
|
+
|
141
|
+
extrapolate: 'clamp',
|
142
|
+
|
143
|
+
});
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
const selected = panX.interpolate({
|
148
|
+
|
149
|
+
inputRange: [xRight, xPos, xLeft],
|
150
|
+
|
151
|
+
outputRange: [0, 1, 0],
|
152
|
+
|
153
|
+
extrapolate: 'clamp',
|
154
|
+
|
155
|
+
});
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
const translateY = Animated.multiply(isIndex, panY);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
const translateX = panX;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
const anim = Animated.multiply(isIndex, scrollY.interpolate({
|
168
|
+
|
169
|
+
inputRange: [0, BREAKPOINT1],
|
170
|
+
|
171
|
+
outputRange: [0, 1],
|
172
|
+
|
173
|
+
extrapolate: 'clamp',
|
174
|
+
|
175
|
+
}));
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
const scale = Animated.add(ONE, Animated.multiply(isIndex, scrollY.interpolate({
|
180
|
+
|
181
|
+
inputRange: [BREAKPOINT1, BREAKPOINT2],
|
182
|
+
|
183
|
+
outputRange: [0, SCALE_END - 1],
|
184
|
+
|
185
|
+
extrapolate: 'clamp',
|
186
|
+
|
187
|
+
})));
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
// [0 => 1]
|
192
|
+
|
193
|
+
let opacity = scrollY.interpolate({
|
194
|
+
|
195
|
+
inputRange: [BREAKPOINT1, BREAKPOINT2],
|
196
|
+
|
197
|
+
outputRange: [0, 1],
|
198
|
+
|
199
|
+
extrapolate: 'clamp',
|
200
|
+
|
201
|
+
});
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
// if i === index: [0 => 0]
|
206
|
+
|
207
|
+
// if i !== index: [0 => 1]
|
208
|
+
|
209
|
+
opacity = Animated.multiply(isNotIndex, opacity);
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
// if i === index: [1 => 1]
|
216
|
+
|
217
|
+
// if i !== index: [1 => 0]
|
218
|
+
|
219
|
+
opacity = opacity.interpolate({
|
220
|
+
|
221
|
+
inputRange: [0, 1],
|
222
|
+
|
223
|
+
outputRange: [1, 0],
|
224
|
+
|
225
|
+
});
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
let markerOpacity = scrollY.interpolate({
|
230
|
+
|
231
|
+
inputRange: [0, BREAKPOINT1],
|
232
|
+
|
233
|
+
outputRange: [0, 1],
|
234
|
+
|
235
|
+
extrapolate: 'clamp',
|
236
|
+
|
237
|
+
});
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
markerOpacity = Animated.multiply(isNotIndex, markerOpacity).interpolate({
|
242
|
+
|
243
|
+
inputRange: [0, 1],
|
244
|
+
|
245
|
+
outputRange: [1, 0],
|
246
|
+
|
247
|
+
});
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
const markerScale = selected.interpolate({
|
252
|
+
|
253
|
+
inputRange: [0, 1],
|
254
|
+
|
255
|
+
outputRange: [1, 1.2],
|
256
|
+
|
257
|
+
});
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
return {
|
262
|
+
|
263
|
+
translateY,
|
264
|
+
|
265
|
+
translateX,
|
266
|
+
|
267
|
+
scale,
|
268
|
+
|
269
|
+
opacity,
|
270
|
+
|
271
|
+
anim,
|
272
|
+
|
273
|
+
center,
|
274
|
+
|
275
|
+
selected,
|
276
|
+
|
277
|
+
markerOpacity,
|
278
|
+
|
279
|
+
markerScale,
|
280
|
+
|
281
|
+
};
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
class AnimatedViews extends React.Component {
|
288
|
+
|
289
|
+
constructor(props) {
|
290
|
+
|
291
|
+
super(props);
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
const { markers } = this.props;
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
const panX = new Animated.Value(0);
|
300
|
+
|
301
|
+
const panY = new Animated.Value(0);
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
const scrollY = panY.interpolate({
|
306
|
+
|
307
|
+
inputRange: [-1, 1],
|
308
|
+
|
309
|
+
outputRange: [1, -1],
|
310
|
+
|
311
|
+
});
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
const scrollX = panX.interpolate({
|
316
|
+
|
317
|
+
inputRange: [-1, 1],
|
318
|
+
|
319
|
+
outputRange: [1, -1],
|
320
|
+
|
321
|
+
});
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
const scale = scrollY.interpolate({
|
326
|
+
|
327
|
+
inputRange: [0, BREAKPOINT1],
|
328
|
+
|
329
|
+
outputRange: [1, 1.6],
|
330
|
+
|
331
|
+
extrapolate: 'clamp',
|
332
|
+
|
333
|
+
});
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
const translateY = scrollY.interpolate({
|
338
|
+
|
339
|
+
inputRange: [0, BREAKPOINT1],
|
340
|
+
|
341
|
+
outputRange: [0, -100],
|
342
|
+
|
343
|
+
extrapolate: 'clamp',
|
344
|
+
|
345
|
+
});
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
const animations = markers.map((m, i) =>
|
350
|
+
|
351
|
+
getMarkerState(panX, panY, scrollY, i));
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
this.state = {
|
356
|
+
|
357
|
+
panX,
|
358
|
+
|
359
|
+
panY,
|
360
|
+
|
361
|
+
animations,
|
362
|
+
|
363
|
+
index: 0,
|
364
|
+
|
365
|
+
canMoveHorizontal: true,
|
366
|
+
|
367
|
+
scrollY,
|
368
|
+
|
369
|
+
scrollX,
|
370
|
+
|
371
|
+
scale,
|
372
|
+
|
373
|
+
translateY,
|
374
|
+
|
375
|
+
region: new AnimatedRegion({
|
376
|
+
|
377
|
+
latitude: LATITUDE,
|
378
|
+
|
379
|
+
longitude: LONGITUDE,
|
380
|
+
|
381
|
+
latitudeDelta: LATITUDE_DELTA,
|
382
|
+
|
383
|
+
longitudeDelta: LONGITUDE_DELTA,
|
384
|
+
|
385
|
+
}),
|
386
|
+
|
387
|
+
};
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
componentDidMount() {
|
394
|
+
|
395
|
+
const { region, panX, panY, scrollX } = this.state;
|
396
|
+
|
397
|
+
const { markers } = this.props;
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
panX.addListener(this.onPanXChange);
|
402
|
+
|
403
|
+
panY.addListener(this.onPanYChange);
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
region.stopAnimation();
|
408
|
+
|
409
|
+
region.timing({
|
410
|
+
|
411
|
+
latitude: scrollX.interpolate({
|
412
|
+
|
413
|
+
inputRange: markers.map((m, i) => i * SNAP_WIDTH),
|
414
|
+
|
415
|
+
outputRange: markers.map(m => m.coordinate.latitude),
|
416
|
+
|
417
|
+
}),
|
418
|
+
|
419
|
+
longitude: scrollX.interpolate({
|
420
|
+
|
421
|
+
inputRange: markers.map((m, i) => i * SNAP_WIDTH),
|
422
|
+
|
423
|
+
outputRange: markers.map(m => m.coordinate.longitude),
|
424
|
+
|
425
|
+
}),
|
426
|
+
|
427
|
+
duration: 0,
|
428
|
+
|
429
|
+
}).start();
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
onStartShouldSetPanResponder = (e) => {
|
436
|
+
|
437
|
+
// we only want to move the view if they are starting the gesture on top
|
438
|
+
|
439
|
+
// of the view, so this calculates that and returns true if so. If we return
|
440
|
+
|
441
|
+
// false, the gesture should get passed to the map view appropriately.
|
442
|
+
|
443
|
+
const { panY } = this.state;
|
444
|
+
|
445
|
+
const { pageY } = e.nativeEvent;
|
446
|
+
|
447
|
+
const topOfMainWindow = ITEM_PREVIEW_HEIGHT + panY.__getValue();
|
448
|
+
|
449
|
+
const topOfTap = screen.height - pageY;
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
return topOfTap < topOfMainWindow;
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
onMoveShouldSetPanResponder = (e) => {
|
460
|
+
|
461
|
+
const { panY } = this.state;
|
462
|
+
|
463
|
+
const { pageY } = e.nativeEvent;
|
464
|
+
|
465
|
+
const topOfMainWindow = ITEM_PREVIEW_HEIGHT + panY.__getValue();
|
466
|
+
|
467
|
+
const topOfTap = screen.height - pageY;
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
return topOfTap < topOfMainWindow;
|
472
|
+
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
onPanXChange = ({ value }) => {
|
478
|
+
|
479
|
+
const { index } = this.state;
|
480
|
+
|
481
|
+
const newIndex = Math.floor(((-1 * value) + (SNAP_WIDTH / 2)) / SNAP_WIDTH);
|
482
|
+
|
483
|
+
if (index !== newIndex) {
|
484
|
+
|
485
|
+
this.setState({ index: newIndex });
|
486
|
+
|
487
|
+
}
|
488
|
+
|
489
|
+
}
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
onPanYChange = ({ value }) => {
|
494
|
+
|
495
|
+
const { canMoveHorizontal, region, scrollY, scrollX, index } = this.state;
|
496
|
+
|
497
|
+
const { markers } = this.props;
|
498
|
+
|
499
|
+
|
500
|
+
|
31
501
|
・・・
|
32
502
|
|
33
503
|
|
34
504
|
|
35
|
-
|
36
|
-
|
37
|
-
i
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
ret
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
tr
|
64
|
-
|
65
|
-
sca
|
66
|
-
|
67
|
-
o
|
68
|
-
|
69
|
-
an
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
}
|
505
|
+
onRegionChange(/* region */) {
|
506
|
+
|
507
|
+
// this.state.region.setValue(region);
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
render() {
|
514
|
+
|
515
|
+
const {
|
516
|
+
|
517
|
+
panX,
|
518
|
+
|
519
|
+
panY,
|
520
|
+
|
521
|
+
animations,
|
522
|
+
|
523
|
+
canMoveHorizontal,
|
524
|
+
|
525
|
+
region,
|
526
|
+
|
527
|
+
} = this.state;
|
528
|
+
|
529
|
+
const { markers } = this.props;
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
return (
|
534
|
+
|
535
|
+
<View style={styles.container}>
|
536
|
+
|
537
|
+
<PanController
|
538
|
+
|
539
|
+
style={styles.container}
|
540
|
+
|
541
|
+
vertical
|
542
|
+
|
543
|
+
horizontal={canMoveHorizontal}
|
544
|
+
|
545
|
+
xMode="snap"
|
546
|
+
|
547
|
+
snapSpacingX={SNAP_WIDTH}
|
548
|
+
|
549
|
+
yBounds={[-1 * screen.height, 0]}
|
550
|
+
|
551
|
+
xBounds={[-screen.width * (markers.length - 1), 0]}
|
552
|
+
|
553
|
+
panY={panY}
|
554
|
+
|
555
|
+
panX={panX}
|
556
|
+
|
557
|
+
onStartShouldSetPanResponder={this.onStartShouldSetPanResponder}
|
558
|
+
|
559
|
+
onMoveShouldSetPanResponder={this.onMoveShouldSetPanResponder}
|
560
|
+
|
561
|
+
>
|
562
|
+
|
563
|
+
<AnimatedMap
|
564
|
+
|
565
|
+
provider={this.props.provider}
|
566
|
+
|
567
|
+
style={styles.map}
|
568
|
+
|
569
|
+
region={region}
|
570
|
+
|
571
|
+
onRegionChange={this.onRegionChange}
|
572
|
+
|
573
|
+
>
|
574
|
+
|
575
|
+
{markers.map((marker, i) => {
|
576
|
+
|
577
|
+
const {
|
578
|
+
|
579
|
+
selected,
|
580
|
+
|
581
|
+
markerOpacity,
|
582
|
+
|
583
|
+
markerScale,
|
584
|
+
|
585
|
+
} = animations[i];
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
return (
|
590
|
+
|
591
|
+
<Marker
|
592
|
+
|
593
|
+
key={marker.id}
|
594
|
+
|
595
|
+
coordinate={marker.coordinate}
|
596
|
+
|
597
|
+
>
|
598
|
+
|
599
|
+
<PriceMarker
|
600
|
+
|
601
|
+
style={{
|
602
|
+
|
603
|
+
opacity: markerOpacity,
|
604
|
+
|
605
|
+
transform: [
|
606
|
+
|
607
|
+
{ scale: markerScale },
|
608
|
+
|
609
|
+
],
|
610
|
+
|
611
|
+
}}
|
612
|
+
|
613
|
+
amount={marker.amount}
|
614
|
+
|
615
|
+
selected={selected}
|
616
|
+
|
617
|
+
/>
|
618
|
+
|
619
|
+
</Marker>
|
620
|
+
|
621
|
+
);
|
622
|
+
|
623
|
+
})}
|
624
|
+
|
625
|
+
</AnimatedMap>
|
626
|
+
|
627
|
+
<View style={styles.itemContainer}>
|
628
|
+
|
629
|
+
{markers.map((marker, i) => {
|
630
|
+
|
631
|
+
const {
|
632
|
+
|
633
|
+
translateY,
|
634
|
+
|
635
|
+
translateX,
|
636
|
+
|
637
|
+
scale,
|
638
|
+
|
639
|
+
opacity,
|
640
|
+
|
641
|
+
} = animations[i];
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
return (
|
646
|
+
|
647
|
+
<Animated.View
|
648
|
+
|
649
|
+
key={marker.id}
|
650
|
+
|
651
|
+
style={[styles.item, {
|
652
|
+
|
653
|
+
opacity,
|
654
|
+
|
655
|
+
transform: [
|
656
|
+
|
657
|
+
{ translateY },
|
658
|
+
|
659
|
+
{ translateX },
|
660
|
+
|
661
|
+
{ scale },
|
662
|
+
|
663
|
+
],
|
664
|
+
|
665
|
+
}]}
|
666
|
+
|
667
|
+
/>
|
668
|
+
|
669
|
+
);
|
670
|
+
|
671
|
+
})}
|
672
|
+
|
673
|
+
</View>
|
674
|
+
|
675
|
+
</PanController>
|
676
|
+
|
677
|
+
</View>
|
678
|
+
|
679
|
+
);
|
680
|
+
|
681
|
+
}
|
80
682
|
|
81
683
|
}
|
82
684
|
|
83
685
|
|
84
686
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
const { markers } = this.props;
|
116
|
-
|
117
|
-
const { region, panX, panY, scrollX } = this.state;
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
panX.addListener(this.onPanXChange);
|
122
|
-
|
123
|
-
panY.addListener(this.onPanYChange);
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
・・・
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
onStartShouldSetPanResponder = (e) => {
|
134
|
-
|
135
|
-
// we only want to move the view if they are starting the gesture on top
|
136
|
-
|
137
|
-
// of the view, so this calculates that and returns true if so. If we return
|
138
|
-
|
139
|
-
// false, the gesture should get passed to the map view appropriately.
|
140
|
-
|
141
|
-
const { panY } = this.state;
|
142
|
-
|
143
|
-
const { pageY } = e.nativeEvent;
|
144
|
-
|
145
|
-
const topOfMainWindow = ITEM_PREVIEW_HEIGHT + panY.__getValue();
|
146
|
-
|
147
|
-
const topOfTap = screen.height - pageY;
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
return topOfTap < topOfMainWindow;
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
onMoveShouldSetPanResponder = (e) => {
|
158
|
-
|
159
|
-
const { panY } = this.state;
|
160
|
-
|
161
|
-
const { pageY } = e.nativeEvent;
|
162
|
-
|
163
|
-
const topOfMainWindow = ITEM_PREVIEW_HEIGHT + panY.__getValue();
|
164
|
-
|
165
|
-
const topOfTap = screen.height - pageY;
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
return topOfTap < topOfMainWindow;
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
onPanXChange = ({ value }) => {
|
176
|
-
|
177
|
-
const { index } = this.state;
|
178
|
-
|
179
|
-
const newIndex = Math.floor(((-1 * value) + (SNAP_WIDTH / 2)) / SNAP_WIDTH);
|
180
|
-
|
181
|
-
if (index !== newIndex) {
|
182
|
-
|
183
|
-
this.setState({ index: newIndex });
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
onPanYChange = ({ value }) => {
|
192
|
-
|
193
|
-
const { markers } = this.props;
|
194
|
-
|
195
|
-
const { canMoveHorizontal, region, scrollY, scrollX, index } = this.state;
|
196
|
-
|
197
|
-
const shouldBeMovable = Math.abs(value) < 2;
|
198
|
-
|
199
|
-
if (shouldBeMovable !== canMoveHorizontal) {
|
200
|
-
|
201
|
-
this.setState({ canMoveHorizontal: shouldBeMovable });
|
202
|
-
|
203
|
-
if (!shouldBeMovable) {
|
204
|
-
|
205
|
-
const { coordinate } = markers[index];
|
206
|
-
|
207
|
-
region.stopAnimation();
|
208
|
-
|
209
|
-
region.timing({
|
210
|
-
|
211
|
-
latitude: scrollY.interpolate({
|
212
|
-
|
213
|
-
inputRange: [0, BREAKPOINT1],
|
214
|
-
|
215
|
-
outputRange: [
|
216
|
-
|
217
|
-
coordinate.latitude,
|
218
|
-
|
219
|
-
coordinate.latitude - (LATITUDE_DELTA * 0.5 * 0.375),
|
220
|
-
|
221
|
-
],
|
222
|
-
|
223
|
-
extrapolate: 'clamp',
|
224
|
-
|
225
|
-
}),
|
226
|
-
|
227
|
-
latitudeDelta: scrollY.interpolate({
|
228
|
-
|
229
|
-
inputRange: [0, BREAKPOINT1],
|
230
|
-
|
231
|
-
outputRange: [LATITUDE_DELTA, LATITUDE_DELTA * 0.5],
|
232
|
-
|
233
|
-
extrapolate: 'clamp',
|
234
|
-
|
235
|
-
}),
|
236
|
-
|
237
|
-
longitudeDelta: scrollY.interpolate({
|
238
|
-
|
239
|
-
inputRange: [0, BREAKPOINT1],
|
240
|
-
|
241
|
-
outputRange: [LONGITUDE_DELTA, LONGITUDE_DELTA * 0.5],
|
242
|
-
|
243
|
-
extrapolate: 'clamp',
|
244
|
-
|
245
|
-
}),
|
246
|
-
|
247
|
-
duration: 0,
|
248
|
-
|
249
|
-
}).start();
|
250
|
-
|
251
|
-
} else {
|
252
|
-
|
253
|
-
region.stopAnimation();
|
254
|
-
|
255
|
-
region.timing({
|
256
|
-
|
257
|
-
latitude: scrollX.interpolate({
|
258
|
-
|
259
|
-
inputRange: markers.map((m, i) => i * SNAP_WIDTH),
|
260
|
-
|
261
|
-
outputRange: markers.map(m => m.coordinate.latitude),
|
262
|
-
|
263
|
-
}),
|
264
|
-
|
265
|
-
longitude: scrollX.interpolate({
|
266
|
-
|
267
|
-
inputRange: markers.map((m, i) => i * SNAP_WIDTH),
|
268
|
-
|
269
|
-
outputRange: markers.map(m => m.coordinate.longitude),
|
270
|
-
|
271
|
-
}),
|
272
|
-
|
273
|
-
duration: 0,
|
274
|
-
|
275
|
-
}).start();
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
}
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
onRegionChange(/* region */) {
|
286
|
-
|
287
|
-
// this.state.region.setValue(region);
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
render() {
|
294
|
-
|
295
|
-
const { markers } = this.props;
|
296
|
-
|
297
|
-
const {
|
298
|
-
|
299
|
-
panX,
|
300
|
-
|
301
|
-
panY,
|
302
|
-
|
303
|
-
animations,
|
304
|
-
|
305
|
-
canMoveHorizontal,
|
306
|
-
|
307
|
-
region,
|
308
|
-
|
309
|
-
} = this.state;
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
console.log('this.props', this.props);
|
314
|
-
|
315
|
-
console.log('this.state', this.state);
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
<AnimatedMap
|
320
|
-
|
321
|
-
provider={this.props.provider}
|
322
|
-
|
323
|
-
style={styles.map}
|
324
|
-
|
325
|
-
region={{
|
326
|
-
|
327
|
-
latitude: 35.6797392,
|
328
|
-
|
329
|
-
longitude: 139.7348855,
|
330
|
-
|
331
|
-
latitudeDelta: 0.0922,
|
332
|
-
|
333
|
-
longitudeDelta: 0.0421,
|
334
|
-
|
335
|
-
}}
|
336
|
-
|
337
|
-
onRegionChange={this.onRegionChange}
|
338
|
-
|
339
|
-
>
|
340
|
-
|
341
|
-
{markers.map((marker, i) => {
|
342
|
-
|
343
|
-
const {
|
344
|
-
|
345
|
-
selected,
|
346
|
-
|
347
|
-
markerOpacity,
|
348
|
-
|
349
|
-
markerScale,
|
350
|
-
|
351
|
-
} = animations[i];
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
return (
|
356
|
-
|
357
|
-
<Marker
|
358
|
-
|
359
|
-
key={marker.id}
|
360
|
-
|
361
|
-
coordinate={marker.coordinate}
|
362
|
-
|
363
|
-
>
|
364
|
-
|
365
|
-
<PriceMarker
|
366
|
-
|
367
|
-
style={{
|
368
|
-
|
369
|
-
opacity: markerOpacity,
|
370
|
-
|
371
|
-
transform: [
|
372
|
-
|
373
|
-
{ scale: markerScale },
|
374
|
-
|
375
|
-
],
|
376
|
-
|
377
|
-
}}
|
378
|
-
|
379
|
-
amount={marker.amount}
|
380
|
-
|
381
|
-
selected={selected}
|
382
|
-
|
383
|
-
/>
|
384
|
-
|
385
|
-
</Marker>
|
386
|
-
|
387
|
-
);
|
388
|
-
|
389
|
-
})}
|
390
|
-
|
391
|
-
</AnimatedMap>
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
・・・
|
687
|
+
AnimatedViews.propTypes = {
|
688
|
+
|
689
|
+
provider: ProviderPropType,
|
690
|
+
|
691
|
+
};
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
...
|
696
|
+
|
697
|
+
|
698
|
+
|
699
|
+
const mapStateToProps = (state) => {
|
700
|
+
|
701
|
+
const markers = _.orderBy(state.markers, ['id'], ['desc']);
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
return { markers };
|
706
|
+
|
707
|
+
};
|
708
|
+
|
709
|
+
|
710
|
+
|
711
|
+
export default connect(mapStateToProps, {
|
712
|
+
|
713
|
+
markersFetch
|
714
|
+
|
715
|
+
})(AnimatedViews);
|
396
716
|
|
397
717
|
```
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
下記のコンポーネントを引っ張ってきています。
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
> AnimatedPlaceView.js
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
```
|
410
|
-
|
411
|
-
import React from 'react';
|
412
|
-
|
413
|
-
import PropTypes from 'prop-types';
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
import {
|
418
|
-
|
419
|
-
StyleSheet,
|
420
|
-
|
421
|
-
Text,
|
422
|
-
|
423
|
-
Animated,
|
424
|
-
|
425
|
-
} from 'react-native';
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
class AnimatedPriceMarker extends React.Component {
|
430
|
-
|
431
|
-
render() {
|
432
|
-
|
433
|
-
const { amount, selected, style } = this.props;
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
const background = selected.interpolate({
|
438
|
-
|
439
|
-
inputRange: [0, 1],
|
440
|
-
|
441
|
-
outputRange: ['#005E7F', '#00A0D8'],
|
442
|
-
|
443
|
-
});
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
const border = selected.interpolate({
|
448
|
-
|
449
|
-
inputRange: [0, 1],
|
450
|
-
|
451
|
-
outputRange: ['#005E7F', '#00A0D8'],
|
452
|
-
|
453
|
-
});
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
return (
|
458
|
-
|
459
|
-
<Animated.View style={[styles.container, style]}>
|
460
|
-
|
461
|
-
<Animated.View
|
462
|
-
|
463
|
-
style={[
|
464
|
-
|
465
|
-
styles.bubble,
|
466
|
-
|
467
|
-
{
|
468
|
-
|
469
|
-
backgroundColor: background,
|
470
|
-
|
471
|
-
borderColor: border,
|
472
|
-
|
473
|
-
},
|
474
|
-
|
475
|
-
]}
|
476
|
-
|
477
|
-
>
|
478
|
-
|
479
|
-
<Text style={styles.dollar}>$</Text>
|
480
|
-
|
481
|
-
<Text style={styles.amount}>{amount}</Text>
|
482
|
-
|
483
|
-
</Animated.View>
|
484
|
-
|
485
|
-
<Animated.View
|
486
|
-
|
487
|
-
style={[styles.arrowBorder, { borderTopColor: border }]}
|
488
|
-
|
489
|
-
/>
|
490
|
-
|
491
|
-
<Animated.View
|
492
|
-
|
493
|
-
style={[styles.arrow, { borderTopColor: background }]}
|
494
|
-
|
495
|
-
/>
|
496
|
-
|
497
|
-
</Animated.View>
|
498
|
-
|
499
|
-
);
|
500
|
-
|
501
|
-
}
|
502
|
-
|
503
|
-
}
|
504
|
-
|
505
|
-
```
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
### コンソール結果
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
> this.props
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
```
|
518
|
-
|
519
|
-
{screenProps: undefined, markers: Array(2), markersFetch: ƒ}
|
520
|
-
|
521
|
-
markers:Array(2)
|
522
|
-
|
523
|
-
0:
|
524
|
-
|
525
|
-
amount:"30"
|
526
|
-
|
527
|
-
coordinate:{longitude: -122.406417, latitude: 37.785834}
|
528
|
-
|
529
|
-
id:"1"
|
530
|
-
|
531
|
-
name:"Test2"
|
532
|
-
|
533
|
-
__proto__:Object1
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
・・・
|
538
|
-
|
539
|
-
```
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
> this.state
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
![state結果](a6ba214d4d823ce4079109d3bd0aa828.png)
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
stateが何も取れていないところから、propsで取得したmarkersがきちんとstateの方にはまっていないのではないかと思うのですが。。すみませんが、お手すきの際にどうぞおたすけください。
|
3
const animationsを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,6 +94,10 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
+
const animations = markers.map((m, i) =>
|
98
|
+
|
99
|
+
getMarkerState(panX, panY, scrollY, i));
|
100
|
+
|
97
101
|
・・・
|
98
102
|
|
99
103
|
|
2
AnimatedPlaceView.jsを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -394,6 +394,114 @@
|
|
394
394
|
|
395
395
|
|
396
396
|
|
397
|
+
下記のコンポーネントを引っ張ってきています。
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
> AnimatedPlaceView.js
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
```
|
406
|
+
|
407
|
+
import React from 'react';
|
408
|
+
|
409
|
+
import PropTypes from 'prop-types';
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
import {
|
414
|
+
|
415
|
+
StyleSheet,
|
416
|
+
|
417
|
+
Text,
|
418
|
+
|
419
|
+
Animated,
|
420
|
+
|
421
|
+
} from 'react-native';
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
class AnimatedPriceMarker extends React.Component {
|
426
|
+
|
427
|
+
render() {
|
428
|
+
|
429
|
+
const { amount, selected, style } = this.props;
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
const background = selected.interpolate({
|
434
|
+
|
435
|
+
inputRange: [0, 1],
|
436
|
+
|
437
|
+
outputRange: ['#005E7F', '#00A0D8'],
|
438
|
+
|
439
|
+
});
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
const border = selected.interpolate({
|
444
|
+
|
445
|
+
inputRange: [0, 1],
|
446
|
+
|
447
|
+
outputRange: ['#005E7F', '#00A0D8'],
|
448
|
+
|
449
|
+
});
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
return (
|
454
|
+
|
455
|
+
<Animated.View style={[styles.container, style]}>
|
456
|
+
|
457
|
+
<Animated.View
|
458
|
+
|
459
|
+
style={[
|
460
|
+
|
461
|
+
styles.bubble,
|
462
|
+
|
463
|
+
{
|
464
|
+
|
465
|
+
backgroundColor: background,
|
466
|
+
|
467
|
+
borderColor: border,
|
468
|
+
|
469
|
+
},
|
470
|
+
|
471
|
+
]}
|
472
|
+
|
473
|
+
>
|
474
|
+
|
475
|
+
<Text style={styles.dollar}>$</Text>
|
476
|
+
|
477
|
+
<Text style={styles.amount}>{amount}</Text>
|
478
|
+
|
479
|
+
</Animated.View>
|
480
|
+
|
481
|
+
<Animated.View
|
482
|
+
|
483
|
+
style={[styles.arrowBorder, { borderTopColor: border }]}
|
484
|
+
|
485
|
+
/>
|
486
|
+
|
487
|
+
<Animated.View
|
488
|
+
|
489
|
+
style={[styles.arrow, { borderTopColor: background }]}
|
490
|
+
|
491
|
+
/>
|
492
|
+
|
493
|
+
</Animated.View>
|
494
|
+
|
495
|
+
);
|
496
|
+
|
497
|
+
}
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
```
|
502
|
+
|
503
|
+
|
504
|
+
|
397
505
|
### コンソール結果
|
398
506
|
|
399
507
|
|
1
selectedのview部分を追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -312,6 +312,82 @@
|
|
312
312
|
|
313
313
|
|
314
314
|
|
315
|
+
<AnimatedMap
|
316
|
+
|
317
|
+
provider={this.props.provider}
|
318
|
+
|
319
|
+
style={styles.map}
|
320
|
+
|
321
|
+
region={{
|
322
|
+
|
323
|
+
latitude: 35.6797392,
|
324
|
+
|
325
|
+
longitude: 139.7348855,
|
326
|
+
|
327
|
+
latitudeDelta: 0.0922,
|
328
|
+
|
329
|
+
longitudeDelta: 0.0421,
|
330
|
+
|
331
|
+
}}
|
332
|
+
|
333
|
+
onRegionChange={this.onRegionChange}
|
334
|
+
|
335
|
+
>
|
336
|
+
|
337
|
+
{markers.map((marker, i) => {
|
338
|
+
|
339
|
+
const {
|
340
|
+
|
341
|
+
selected,
|
342
|
+
|
343
|
+
markerOpacity,
|
344
|
+
|
345
|
+
markerScale,
|
346
|
+
|
347
|
+
} = animations[i];
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
return (
|
352
|
+
|
353
|
+
<Marker
|
354
|
+
|
355
|
+
key={marker.id}
|
356
|
+
|
357
|
+
coordinate={marker.coordinate}
|
358
|
+
|
359
|
+
>
|
360
|
+
|
361
|
+
<PriceMarker
|
362
|
+
|
363
|
+
style={{
|
364
|
+
|
365
|
+
opacity: markerOpacity,
|
366
|
+
|
367
|
+
transform: [
|
368
|
+
|
369
|
+
{ scale: markerScale },
|
370
|
+
|
371
|
+
],
|
372
|
+
|
373
|
+
}}
|
374
|
+
|
375
|
+
amount={marker.amount}
|
376
|
+
|
377
|
+
selected={selected}
|
378
|
+
|
379
|
+
/>
|
380
|
+
|
381
|
+
</Marker>
|
382
|
+
|
383
|
+
);
|
384
|
+
|
385
|
+
})}
|
386
|
+
|
387
|
+
</AnimatedMap>
|
388
|
+
|
389
|
+
|
390
|
+
|
315
391
|
・・・
|
316
392
|
|
317
393
|
```
|