react-crud-mobile 1.0.641 → 1.0.643

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.641",
2
+ "version": "1.0.643",
3
3
  "license": "MIT",
4
4
  "description": "Uma biblioteca de componentes para React Native",
5
5
  "main": "dist/index.js",
@@ -1,8 +1,16 @@
1
- import React, { useState } from 'react';
1
+ import React, { useRef, useState } from 'react';
2
2
  import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
3
  import UIChildren from '../UIChildren';
4
- import { StyleSheet, TouchableHighlight, View } from 'react-native';
5
- import { InView } from 'react-native-intersection-observer';
4
+ import {
5
+ StyleSheet,
6
+ TouchableHighlight,
7
+ ScrollView,
8
+ View,
9
+ Text,
10
+ Dimensions,
11
+ findNodeHandle,
12
+ UIManager,
13
+ } from 'react-native';
6
14
 
7
15
  interface UIListRowType extends ChildType {
8
16
  item: any;
@@ -37,6 +45,19 @@ export default function UIListRow(props: UIListRowType) {
37
45
  const ListItem = () => {
38
46
  let [updateIndex, setUpdateIndex] = useState(0);
39
47
  let key = scope.key('item');
48
+ const viewRef = useRef(null);
49
+ const [visible, setVisible] = useState(false);
50
+ const windowHeight = Dimensions.get('window').height;
51
+ const checkIfVisible = () => {
52
+ const nodeHandle = findNodeHandle(viewRef.current);
53
+
54
+ if (nodeHandle && !visible) {
55
+ UIManager.measure(nodeHandle, (x, y, width, height, pageX, pageY) => {
56
+ const isVisible = pageY >= 0 && pageY + height <= windowHeight;
57
+ setVisible(isVisible);
58
+ });
59
+ }
60
+ };
40
61
 
41
62
  const getRowStyle = () => {
42
63
  let css = row.getStyle('row', { ...styles.row });
@@ -54,31 +75,45 @@ export default function UIListRow(props: UIListRowType) {
54
75
  setUpdateIndex(++updateIndex);
55
76
  };
56
77
 
78
+ const Child = () => {
79
+ return (
80
+ <>
81
+ {visible && (
82
+ <UIChildren scope={row} crud={row.crud}>
83
+ {props.children}
84
+ </UIChildren>
85
+ )}
86
+ </>
87
+ );
88
+ };
89
+
57
90
  if (!original.click) {
58
91
  return (
59
- <View key={key} style={getRowStyle()}>
60
- <UIChildren scope={row} crud={row.crud}>
61
- {props.children}
62
- </UIChildren>
92
+ <View
93
+ key={key}
94
+ style={getRowStyle()}
95
+ onLayout={checkIfVisible}
96
+ ref={viewRef}
97
+ >
98
+ <Child />
63
99
  </View>
64
100
  );
65
101
  }
102
+
66
103
  return (
67
- <InView>
68
- <TouchableHighlight
69
- key={key}
70
- style={getRowStyle()}
71
- underlayColor={'transparent'}
72
- onPress={e => {
73
- e.stopPropagation();
74
- onClick(item);
75
- }}
76
- >
77
- <UIChildren scope={row} crud={row.crud}>
78
- {props.children}
79
- </UIChildren>
80
- </TouchableHighlight>
81
- </InView>
104
+ <TouchableHighlight
105
+ key={key}
106
+ style={getRowStyle()}
107
+ ref={viewRef}
108
+ underlayColor={'transparent'}
109
+ onLayout={checkIfVisible}
110
+ onPress={e => {
111
+ e.stopPropagation();
112
+ onClick(item);
113
+ }}
114
+ >
115
+ <Child />
116
+ </TouchableHighlight>
82
117
  );
83
118
  };
84
119