react-crud-mobile 1.0.640 → 1.0.642

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.640",
2
+ "version": "1.0.642",
3
3
  "license": "MIT",
4
4
  "description": "Uma biblioteca de componentes para React Native",
5
5
  "main": "dist/index.js",
@@ -48,6 +48,7 @@
48
48
  "react-dom": "19.0.0",
49
49
  "react-native": "0.79.2",
50
50
  "react-native-gesture-handler": "~2.24.0",
51
+ "react-native-intersection-observer": "^0.2.1",
51
52
  "react-native-reanimated": "~3.17.4",
52
53
  "react-native-safe-area-context": "5.4.0",
53
54
  "react-native-screens": "~4.10.0",
@@ -1,7 +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';
4
+ import {
5
+ StyleSheet,
6
+ TouchableHighlight,
7
+ ScrollView,
8
+ View,
9
+ Text,
10
+ Dimensions,
11
+ findNodeHandle,
12
+ UIManager,
13
+ } from 'react-native';
5
14
 
6
15
  interface UIListRowType extends ChildType {
7
16
  item: any;
@@ -36,6 +45,18 @@ export default function UIListRow(props: UIListRowType) {
36
45
  const ListItem = () => {
37
46
  let [updateIndex, setUpdateIndex] = useState(0);
38
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
+ if (nodeHandle) {
54
+ UIManager.measure(nodeHandle, (x, y, width, height, pageX, pageY) => {
55
+ const isVisible = pageY >= 0 && pageY + height <= windowHeight;
56
+ setVisible(isVisible);
57
+ });
58
+ }
59
+ };
39
60
 
40
61
  const getRowStyle = () => {
41
62
  let css = row.getStyle('row', { ...styles.row });
@@ -53,28 +74,44 @@ export default function UIListRow(props: UIListRowType) {
53
74
  setUpdateIndex(++updateIndex);
54
75
  };
55
76
 
77
+ const Child = () => {
78
+ return (
79
+ <>
80
+ {visible && (
81
+ <UIChildren scope={row} crud={row.crud}>
82
+ {props.children}
83
+ </UIChildren>
84
+ )}
85
+ </>
86
+ );
87
+ };
88
+
56
89
  if (!original.click) {
57
90
  return (
58
- <View key={key} style={getRowStyle()}>
59
- <UIChildren scope={row} crud={row.crud}>
60
- {props.children}
61
- </UIChildren>
91
+ <View
92
+ key={key}
93
+ style={getRowStyle()}
94
+ onLayout={checkIfVisible}
95
+ ref={viewRef}
96
+ >
97
+ <Child />
62
98
  </View>
63
99
  );
64
100
  }
101
+
65
102
  return (
66
103
  <TouchableHighlight
67
104
  key={key}
68
105
  style={getRowStyle()}
106
+ ref={viewRef}
69
107
  underlayColor={'transparent'}
108
+ onLayout={checkIfVisible}
70
109
  onPress={e => {
71
110
  e.stopPropagation();
72
111
  onClick(item);
73
112
  }}
74
113
  >
75
- <UIChildren scope={row} crud={row.crud}>
76
- {props.children}
77
- </UIChildren>
114
+ <Child />
78
115
  </TouchableHighlight>
79
116
  );
80
117
  };