Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
695 lines (574 loc) · 23.1 KB
/
Copy pathApp.js
File metadata and controls
695 lines (574 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
import React from 'react';
import { StyleSheet, Text, View, Image, Dimensions, ListView, FlatList, TouchableOpacity} from 'react-native';
import Data from './UserData.js'
let CUSTOM_HEIGHT_TIMEOUT_MS = 10000
// const PERFECTLY_ON_SCREEN = 0; // `perfectly on screen`
// const IRRELEVANT = 1; // `irrelevant`
// const NEITHER_STARTS_ON_SCREEN_NOR_ENDS = 2; // `view neither starts on screen nor ends`
// const STARTS_BUT_DOESNT_END = 3; // `view starts on screen but doesn't end`
// const ENDS_BUT_DOESNT_START = 4; // `view ends on screen but doesn't starts`;
class App extends React.Component {
constructor(props) {
super(props);
this.screenHeight = Math.round(Dimensions.get('window').height);
this.itemsMap = new Map();
this.deepestScrolledRow = {rowId: '',rowY: 0}
this.lastScroll = 0;
this.nowScrollPosition = 0;
this.callOnce = 0;
this.upperBar=0;
this.lowerBar=0;
this.screenTypeDInfo = {itemId: 'not D'};
this.lastScrollingDirection = 'neutral';
this.rerenderedInfo = {
isSizeChanged : 1,
sizeChangeSection : 'nowhere',
sizeChangeType: 'neutral',
sizeChangedValue: 0,
}
ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
dataSource: ds.cloneWithRows(Data),
};
}
componentDidMount(){
// console.log(this.refs.x.getMetrics, 4000);
}
// onRowLayoutMade = (rowKey, event) => {
onRowLayoutMade = (rowIdentifier, event) => {
let { x, y, width, height } = event.nativeEvent.layout
const itemProps = {
seenCount: 0,
yCoordinate: Math.ceil(y),
height: Math.floor(height),
}
if(y >= (1.5)*this.screenHeight && this.callOnce === 0){
++this.callOnce;
this.oneTimeCall();
}
let item = this.itemsMap.get(rowIdentifier)
if (item === undefined) {
this.itemsMap.set(rowIdentifier, itemProps)
} else {
// TODO:later
// if 'expansion' is happening then view's previous layout should be above the (this.upperBar). then only the this.upperBar would get shift to
// downwards
if(Math.floor(height) - item.height > 0){
if(item.y + item.height < this.upperBar) {
this.rerenderedInfo.sizeChangedValue += Math.floor(height) - item.height
console.log('@@@@@:expansion noticed in ', rowIdentifier)
}
}
// if 'shrinking' is happening then check if previous layout of view is above (this.lowerBar) or not.
// finding how much this.lowerBar is gonna shift in upward direction.
if(Math.floor(height) - item.height < 0){
if(item.yCoordinate + item.height <= this.lowerBar) {
this.rerenderedInfo.sizeChangedValue += Math.floor(height) - item.height
console.log('@@@@@:shrinking noticed in ', rowIdentifier)
}
}
// TODO: focus on this
if (this.rerenderedInfo.isSizeChanged === 1) {
this.rerenderedInfo.isSizeChanged = 0
// look at the first rerendered view to find where change happened
if (item.yCoordinate-this.nowScrollPosition < 0) {
this.rerenderedInfo.sizeChangeSection = 'above'
}
if (item.yCoordinate - this.nowScrollPosition >= 0 && item.yCoordinate - this.nowScrollPosition <= this.screenHeight) {
this.rerenderedInfo.sizeChangeSection = 'onscreen'
}
setTimeout(() => {
console.log('@@@@@@ SizeChangeed: ', this.rerenderedInfo.sizeChangedValue);
// in shrinking "this.rerenderedInfo.sizeChangedValue" would be negative so simply add it in both
// shrinking and expansion
if (this.rerenderedInfo.sizeChangedValue < 0)
this.rerenderedInfo.sizeChangeType = 'shrink'
if (this.rerenderedInfo.sizeChangedValue > 0)
this.rerenderedInfo.sizeChangeType = 'expand'
// TODO:Focus on this on this one too.
if (this.screenTypeDInfo.itemId === rowIdentifier) { // the view that changed size was the ScreenType D's view
this.screenTypeDInfo.itemId = 'not D'
}
if ((this.rerenderedInfo.sizeChangeSection === 'onscreen' || this.rerenderedInfo.sizeChangeSection === 'above')
&& this.rerenderedInfo.sizeChangeType !== 'neutral') {
this.viewsRerendered(); // call for whole process
}
}, 0);
}
itemProps.seenCount = this.itemsMap.get(rowIdentifier).seenCount
this.itemsMap.set(rowIdentifier, itemProps)
}
}
searchRangeWhenListGoingUp = () => {
let rangeMin, rangeMax
if (this.screenTypeDInfo.itemId !== 'not D') { // last screen type was D, then search space is a little bit different
if (this.lastScrollingDirection === 'up') { // U D U
rangeMin = this.upperBar - this.rerenderedInfo.sizeChangedValue
rangeMax = this.nowScrollPosition + this.screenHeight
}
if (this.lastScrollingDirection === 'down') { // D D U
rangeMin = this.lowerBar + this.rerenderedInfo.sizeChangedValue
rangeMax = this.nowScrollPosition + this.screenHeight
}
}
else{
rangeMin = this.lowerBar + this.rerenderedInfo.sizeChangedValue
rangeMax = this.nowScrollPosition + this.screenHeight
}
return {rangeMin, rangeMax}
}
searchRangeWhenListGoingDown = () => {
let rangeMin, rangeMax
if (this.screenTypeDInfo.itemId !== 'not D') { // last screen type was D, then search space is a little bit different
if (this.lastScrollingDirection === 'up') { // U D D
rangeMin = this.nowScrollPosition
rangeMax = this.upperBar + this.rerenderedInfo.sizeChangedValue
}
if (this.lastScrollingDirection === 'down') { // D D D
rangeMin = this.nowScrollPosition
rangeMax = this.lowerBar + this.rerenderedInfo.sizeChangedValue
}
}
else{
rangeMin = this.nowScrollPosition
rangeMax = this.upperBar + this.rerenderedInfo.sizeChangedValue
}
return {rangeMin, rangeMax}
}
viewsRerendered = () => {
// before coming to here scroll would be updated already;
let rangeObj;
if (this.rerenderedInfo.sizeChangeType === 'shrink') {
rangeObj = this.searchRangeWhenListGoingUp()
// console.log('ranges: ', rangeObj.rangeMin, rangeObj.rangeMax)
// console.log('@@@@minRange: ', rangeObj.rangeMin, '@@@@maxRange', rangeObj.rangeMax)
this.raiseSeenCount(rangeObj.rangeMin, rangeObj.rangeMax)
this.lastScrollingDirection = 'up'
}
if (this.rerenderedInfo.sizeChangeType === 'expand' && this.rerenderedInfo.sizeChangeSection === 'above') {
rangeObj = this.searchRangeWhenListGoingDown()
this.raiseSeenCount(rangeObj.rangeMin, rangeObj.rangeMax)
this.lastScrollingDirection = 'down'
}
this.updateBarValues()
this.rerenderedInfo.sizeChangeSection = 'nowhere'
this.rerenderedInfo.isSizeChanged = 1
this.rerenderedInfo.sizeChangeType = 'neutral'
this.rerenderedInfo.sizeChangedValue = 0
}
viewStatusOnScreen = (value) => { // view starts and ends completely on screen
const startY = value.yCoordinate - this.nowScrollPosition
const endY = startY + value.height
if((startY < 0 && endY < 0) || (startY > this.screenHeight && endY > this.screenHeight)) return 1
if(startY >= 0 && endY <= this.screenHeight) return 0
if(startY < 0 && endY > this.screenHeight) return 2
if(startY >= 0 && endY > this.screenHeight) return 3
if(startY < 0 && endY <= this.screenHeight) return 4
}
screenStatus = () => {
let viewStarts = 0, viewEnds = 0
for (let [key, value] of this.itemsMap.entries()) {
let viewStatus = this.viewStatusOnScreen(value)
if (viewStatus === 1) continue
if (viewStatus === 0) return 'E'
if (viewStatus === 3) viewStarts = 1
if (viewStatus === 4) viewEnds = 1
}
if (viewStarts === 0 && viewEnds === 0) return 'D'
if (viewStarts === 1 && viewEnds === 1) return 'A'
if (viewStarts === 1 && viewEnds === 0) return 'B'
if (viewStarts === 0 && viewEnds === 1) return 'C'
}
updateBarValues = () => {
let updateLowerBar = Number.NEGATIVE_INFINITY
let updateUpperBar = Number.POSITIVE_INFINITY
let SS = this.screenStatus()
this.screenTypeDInfo.itemId = 'not D'
if(SS === 'A' || SS === 'B'){
for (let [key, value] of this.itemsMap.entries()) {
if(this.viewStatusOnScreen(value) === 3){
updateUpperBar = updateLowerBar = value.yCoordinate
}
}
}
if(SS === 'C'){
for (let [key, value] of this.itemsMap.entries()) {
if(this.viewStatusOnScreen(value) === 4){
updateUpperBar = updateLowerBar = value.yCoordinate + value.height
}
}
}
if (SS === 'D') {
console.log('screenTypeD')
for (let [key, value] of this.itemsMap.entries()) {
const viewStartY = value.yCoordinate
const viewEndY = value.yCoordinate + value.height
if (viewStartY < this.nowScrollPosition && viewEndY > this.nowScrollPosition + this.screenHeight) {
this.screenTypeDInfo.itemId = key // id of view for screen type D got stored
this.lowerBar = value.yCoordinate + value.height
this.upperBar = value.yCoordinate
break
}
}
}
if(SS === 'E'){
for (let [key, value] of this.itemsMap.entries()) {
if(this.viewStatusOnScreen(value) === 0){
updateLowerBar = Math.max(updateLowerBar, value.yCoordinate + value.height)
updateUpperBar = Math.min(updateUpperBar, value.yCoordinate)
}
}
}
if(updateLowerBar !== Number.NEGATIVE_INFINITY)
this.lowerBar = updateLowerBar
if(updateUpperBar !== Number.POSITIVE_INFINITY)
this.upperBar = updateUpperBar
console.log('@@@upperBar: ', this.upperBar, ' @@@lowerBar: ', this.lowerBar);
}
raiseSeenCount = (rangeMin, rangeMax) => {
console.log('@@@@@: NowScroll ', this.nowScrollPosition)
console.log('@@@@minRange: ', rangeMin, '@@@@maxRange', rangeMax)
for (let [key, value] of this.itemsMap.entries()) {
if(value.yCoordinate >= rangeMin && value.yCoordinate + value.height <= rangeMax){
++value.seenCount
console.log(key, value.seenCount, 'got updated@@@@@@@@@')
console.log('@@@@@@@@: ', value.yCoordinate, value.height)
}
}
}
oneTimeCall = () => {
let rangeMin = this.nowScrollPosition, rangeMax = this.screenHeight + this.nowScrollPosition
this.raiseSeenCount(rangeMin, rangeMax)
this.updateBarValues()
}
func = () => {
console.log('@@@@@@######################################################')
let rangeObj
if (this.nowScrollPosition > this.lastScroll) { // list going up
rangeObj = this.searchRangeWhenListGoingUp()
}else{ // list going down
rangeObj = this.searchRangeWhenListGoingDown()
}
// console.log('@@@@minRange: ', rangeObj.rangeMin, '@@@@maxRange', rangeObj.rangeMax)
this.raiseSeenCount(rangeObj.rangeMin, rangeObj.rangeMax)
this.updateBarValues()
// console.log(`upperBar: ${this.upperBar} lowerBar: ${this.lowerBar}`);
if (this.lastScroll > this.nowScrollPosition) {
this.lastScrollingDirection = 'down' // list moved down
}
if (this.lastScroll < this.nowScrollPosition) {
this.lastScrollingDirection = 'up' // list moved up
}
this.lastScroll = this.nowScrollPosition
}
scrollMomentumStopped = (event) => {
this.nowScrollPosition = Math.round(event.nativeEvent.contentOffset.y);
this.func();
}
handleScroll = (event) => {
// TODO: have to update the scroll for 'Edge Case 1'
this.nowScrollPosition = Math.round(event.nativeEvent.contentOffset.y);
}
render() {
return (
<ListView
style = {styles.listContainer}
dataSource = {this.state.dataSource}
renderRow={this.Row}
//
onScroll={this.handleScroll}
onMomentumScrollEnd={this.scrollMomentumStopped}
//
renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator} />}>
</ListView>
);
}
Row = (rowData, _ , rowId) => {
return(
<RowItem
rowData={ rowData }
rowId={ rowId }
onRowLayoutMade={ this.onRowLayoutMade }
/>
)
}
}
class RowItem extends React.Component {
constructor(props) {
super(props)
this.state = { useCustomHeight: false };
}
componentDidMount() {
if (this.props.rowData.email === 'aiden.lucas@example.com' || this.props.rowData.email === 'mario.walters@example.com')
setTimeout(() => this.setState({ useCustomHeight: true }), 50000)
}
render() {
const { rowData, rowId, onRowLayoutMade } = this.props
const styleList = [ styles.rowContainer, this.state.useCustomHeight ? { height: 100 } : {} ]
return (
<View style={styleList}
onLayout={e => onRowLayoutMade(rowData.email, e)}>
<Image source={{ uri: rowData.picture.large}} style={styles.photo} />
<Text style={styles.text}>
{`${rowData.name.first} ${rowData.name.last} ${rowId}`}
</Text>
<View style={styles.emptyView}/>
</View>
);
}
}
export default App;
const styles = StyleSheet.create({
listContainer: {
flex: 1,
},
rowContainer: {
flex: 1,
padding: 12,
flexDirection: 'row',
alignItems: 'center',
height:400,
},
text: {
marginLeft: 12,
fontSize: 16,
},
photo: {
height: 40,
width: 40,
borderRadius: 20,
},
separator: {
flex: 1,
height: 10,
backgroundColor: '#8E8E8E',
},
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// my code
onRowLayoutMade = (rowIdentifier, event) => {
let { x, y, width, height } = event.nativeEvent.layout
if(height !== 0)
console.log('@@@@renderingData ', rowIdentifier, y, height)
const itemProps = {
seenCount: 0,
yCoordinate: Math.ceil(y),
height: Math.floor(height),
}
if(y >= 1.5*this.screenHeight && this.callOnce === 0){
++this.callOnce;
this.oneTimeCall()
}
let item = this.itemsMap.get(rowIdentifier)
if (item === undefined) {
if(itemProps.height === 0 || rowIdentifier === 'PRODUCT') return // let's ditch these
// console.log('@@@rendered ', rowIdentifier, ' ', height)
this.itemsMap.set(rowIdentifier, itemProps)
} else {
// view rerendering would shift the upperBar
if(item.y + item.height < this.upperBar) {
this.rerenderedInfo.sizeChangedAboveUpperBar += Math.floor(height) - item.height
console.log('@@@@@:expansion noticed in ', rowIdentifier)
}
// view rerendering would shift the LowerBar
if(item.yCoordinate + item.height <= this.lowerBar) {
this.rerenderedInfo.sizeChangedAboveLowerBar += Math.floor(height) - item.height
console.log('@@@@@:shrinking noticed in ', rowIdentifier)
}
// TODO: focus on this about after what delay we are gonna start this process.
if (this.rerenderedInfo.isSizeChanged === 1) {
this.rerenderedInfo.isSizeChanged = 0
setTimeout(() => {
console.log('@@@@Size changed above UpperBar', this.rerenderedInfo.sizeChangedAboveUpperBar)
console.log('@@@@Size changed above LowerBar', this.rerenderedInfo.sizeChangedAboveLowerBar)
this.viewsRerendered() // call for whole process
}, 0);
}
itemProps.seenCount = this.itemsMap.get(rowIdentifier).seenCount
this.itemsMap.set(rowIdentifier, itemProps)
}
}
searchRangeWhenListGoingUp = () => {
let rangeMin, rangeMax
if (this.screenTypeDInfo.itemId !== 'not D') { // last screen type was D, then search space is a little bit different
if (this.lastScrollingDirection === 'up') { // U D U
rangeMin = this.upperBar
rangeMax = this.nowScrollPosition + this.screenHeight
}
if (this.lastScrollingDirection === 'down') { // D D U
rangeMin = this.lowerBar
rangeMax = this.nowScrollPosition + this.screenHeight
}
}
else{
rangeMin = this.lowerBar
rangeMax = this.nowScrollPosition + this.screenHeight
}
return {rangeMin, rangeMax}
}
searchRangeWhenListGoingDown = () => {
let rangeMin, rangeMax
if (this.screenTypeDInfo.itemId !== 'not D') { // last screen type was D, then search space is a little bit different
if (this.lastScrollingDirection === 'up') { // U D D
rangeMin = this.nowScrollPosition
rangeMax = this.upperBar
}
if (this.lastScrollingDirection === 'down') { // D D D
rangeMin = this.nowScrollPosition
rangeMax = this.lowerBar
}
}
else{
rangeMin = this.nowScrollPosition
rangeMax = this.upperBar
}
return {rangeMin, rangeMax}
}
viewsRerendered = () => {
// before coming to here scroll would be updated already;
this.lowerBar += this.rerenderedInfo.sizeChangedAboveLowerBar
this.upperBar += this.rerenderedInfo.sizeChangedAboveUpperBar
this.raiseSeenCount(this.nowScrollPosition, this.upperBar)
this.raiseSeenCount(this.lowerBar, this.nowScrollPosition + this.screenHeight)
this.updateBarValues()
//TODO: how to decide in which direction screen moved
// we need to update direction only if size change results in D type screen
if(this.screenStatus === 'D'){
if(this.rerenderedInfo.sizeChangedAboveLowerBar > 0){
this.lastScrollingDirection = 'down'
}
if(this.rerenderedInfo.sizeChangedAboveLowerBar < 0){
this.lastScrollingDirection = 'up'
}
}
this.rerenderedInfo.isSizeChanged = 1
this.rerenderedInfo.sizeChangedAboveLowerBar = 0
this.rerenderedInfo.sizeChangedAboveUpperBar = 0
}
viewStatusOnScreen = (value) => { // view starts and ends completely on screen
const startY = value.yCoordinate - this.nowScrollPosition
const endY = startY + value.height
if((startY < 0 && endY < 0) || (startY > this.screenHeight && endY > this.screenHeight)) return 1
if(startY >= 0 && endY <= this.screenHeight) return 0
if(startY < 0 && endY > this.screenHeight) return 2
if(startY >= 0 && endY > this.screenHeight) return 3
if(startY < 0 && endY <= this.screenHeight) return 4
}
screenStatus = () => {
let viewStarts = 0, viewEnds = 0
for (let [key, value] of this.itemsMap.entries()) {
let viewStatus = this.viewStatusOnScreen(value)
if (viewStatus === 1) continue
if (viewStatus === 0) return 'E'
if (viewStatus === 3) viewStarts = 1
if (viewStatus === 4) viewEnds = 1
}
if (viewStarts === 0 && viewEnds === 0) return 'D'
if (viewStarts === 1 && viewEnds === 1) return 'A'
if (viewStarts === 1 && viewEnds === 0) return 'B'
if (viewStarts === 0 && viewEnds === 1) return 'C'
}
updateBarValues = () => {
let updateLowerBar = Number.NEGATIVE_INFINITY
let updateUpperBar = Number.POSITIVE_INFINITY
let SS = this.screenStatus()
this.screenTypeDInfo.itemId = 'not D'
if(SS === 'A' || SS === 'B'){
for (let [key, value] of this.itemsMap.entries()) {
if(this.viewStatusOnScreen(value) === 3){
updateUpperBar = updateLowerBar = value.yCoordinate
}
}
}
if(SS === 'C'){
for (let [key, value] of this.itemsMap.entries()) {
if(this.viewStatusOnScreen(value) === 4){
updateUpperBar = updateLowerBar = value.yCoordinate + value.height
}
}
}
if (SS === 'D') {
console.log('screenTypeD')
for (let [key, value] of this.itemsMap.entries()) {
const viewStartY = value.yCoordinate
const viewEndY = value.yCoordinate + value.height
if (viewStartY < this.nowScrollPosition && viewEndY > this.nowScrollPosition + this.screenHeight) {
this.screenTypeDInfo.itemId = key // id of view for screen type D got stored
this.lowerBar = value.yCoordinate + value.height
this.upperBar = value.yCoordinate
break
}
}
}
if(SS === 'E'){
for (let [key, value] of this.itemsMap.entries()) {
if(this.viewStatusOnScreen(value) === 0){
updateLowerBar = Math.max(updateLowerBar, value.yCoordinate + value.height)
updateUpperBar = Math.min(updateUpperBar, value.yCoordinate)
}
}
}
if(updateLowerBar !== Number.NEGATIVE_INFINITY)
this.lowerBar = updateLowerBar
if(updateUpperBar !== Number.POSITIVE_INFINITY)
this.upperBar = updateUpperBar
console.log('@@@upperBar: ', this.upperBar, ' @@@lowerBar: ', this.lowerBar);
}
raiseSeenCount = (rangeMin, rangeMax) => {
console.log('@@@@@: NowScroll ', this.nowScrollPosition)
console.log('@@@@minRange: ', rangeMin, '@@@@maxRange', rangeMax)
for (let [key, value] of this.itemsMap.entries()) {
if(value.yCoordinate >= rangeMin && value.yCoordinate + value.height <= rangeMax){
++value.seenCount
console.log(key, value.seenCount, 'got updated@@@@@@@@@')
console.log('@@@@@@@@: ', value.yCoordinate, value.height)
}
}
}
oneTimeCall = () => {
let rangeMin = this.nowScrollPosition, rangeMax = this.screenHeight + this.nowScrollPosition
this.raiseSeenCount(rangeMin, rangeMax)
this.updateBarValues()
}
itemOnDScreen = () => {
for (let [key, value] of this.itemsMap.entries()) {
const viewStartY = value.yCoordinate
const viewEndY = value.yCoordinate + value.height
if (viewStartY < this.nowScrollPosition && viewEndY > this.nowScrollPosition + this.screenHeight) {
return key;
}
}
return 'not D'
}
func = () => {
console.log('@@@@@@######################################################')
let rangeObj
if (this.nowScrollPosition > this.lastScroll) { // list going up
rangeObj = this.searchRangeWhenListGoingUp()
}else{ // list going down
rangeObj = this.searchRangeWhenListGoingDown()
}
// console.log('@@@@minRange: ', rangeObj.rangeMin, '@@@@maxRange', rangeObj.rangeMax)
this.raiseSeenCount(rangeObj.rangeMin, rangeObj.rangeMax)
// don't update the movement direction if screen type was D and after scrolling it is still D and the same view is there on screen
if(this.screenStatus() === 'D' && this.screenTypeDInfo.itemId === this.itemOnDScreen()){
}else{
if (this.lastScroll > this.nowScrollPosition) {
this.lastScrollingDirection = 'down' // list moved down
}
if (this.lastScroll < this.nowScrollPosition) {
this.lastScrollingDirection = 'up' // list moved up
}
}
this.updateBarValues()
this.lastScroll = this.nowScrollPosition
}
scrollMomentumStopped = (event) => {
this.nowScrollPosition = Math.ceil(event.nativeEvent.contentOffset.y)
console.log('@@@@scrollMomentumStopped')
this.func()
}
handleScroll = (event) => {
// TODO: have to update the scroll for 'Edge Case 1'
// this.nowScrollPosition = Math.floor(event.nativeEvent.contentOffset.y)
}