react-crud-mobile 1.0.644 → 1.0.646

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.644",
2
+ "version": "1.0.646",
3
3
  "license": "MIT",
4
4
  "description": "Uma biblioteca de componentes para React Native",
5
5
  "main": "dist/index.js",
@@ -44,11 +44,10 @@
44
44
  "@react-native-vector-icons/ionicons": "^7.4.0",
45
45
  "@react-native-vector-icons/material-icons": "^0.0.1",
46
46
  "react": "19.0.0",
47
- "react-crud-utils": "^0.1.260",
47
+ "react-crud-utils": "^0.1.261",
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",
52
51
  "react-native-reanimated": "~3.17.4",
53
52
  "react-native-safe-area-context": "5.4.0",
54
53
  "react-native-screens": "~4.10.0",
@@ -2,14 +2,12 @@ import React, { useRef, useState } from 'react';
2
2
  import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
3
  import UIChildren from '../UIChildren';
4
4
  import {
5
- StyleSheet,
6
- TouchableHighlight,
7
- ScrollView,
8
- View,
9
- Text,
10
5
  Dimensions,
11
6
  findNodeHandle,
7
+ StyleSheet,
8
+ TouchableHighlight,
12
9
  UIManager,
10
+ View,
13
11
  } from 'react-native';
14
12
 
15
13
  interface UIListRowType extends ChildType {
@@ -38,24 +36,43 @@ export default function UIListRow(props: UIListRowType) {
38
36
  })
39
37
  );
40
38
 
41
- const viewRef = useRef(null);
42
- const [visible, setVisible] = useState(false);
43
- const windowHeight = Dimensions.get('window').height;
44
- const checkIfVisible = () => {
45
- const nodeHandle = findNodeHandle(viewRef.current);
46
-
47
- if (nodeHandle && !visible) {
48
- UIManager.measure(nodeHandle, (x, y, width, height, pageX, pageY) => {
49
- const isVisible = pageY >= 0 && pageY + height <= windowHeight;
50
- setVisible(isVisible);
51
- });
39
+ const targetRef = useRef(null);
40
+ const [visivel, setVisivel] = useState(false);
41
+
42
+ const onScroll = () => {
43
+ if (!visivel) {
44
+ const handle = findNodeHandle(targetRef.current);
45
+ if (handle) {
46
+ UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
47
+ const windowHeight = Dimensions.get('window').height;
48
+ const topoVisivel = pageY >= 0 && pageY < windowHeight;
49
+ const fundoVisivel =
50
+ pageY + height > 0 && pageY + height < windowHeight;
51
+ setVisivel(topoVisivel || fundoVisivel);
52
+ });
53
+ }
52
54
  }
53
55
  };
54
56
 
57
+ row.onScroll = onScroll;
58
+
55
59
  const onClick = (item: any) => {
56
60
  row.call('click', { value: item, item, edit: true, index });
57
61
  };
58
62
 
63
+ const Child = () => {
64
+ if (!visivel) {
65
+ return <></>;
66
+ }
67
+ return (
68
+ <>
69
+ <UIChildren scope={row} crud={row.crud}>
70
+ {props.children}
71
+ </UIChildren>
72
+ </>
73
+ );
74
+ };
75
+
59
76
  const ListItem = () => {
60
77
  let [updateIndex, setUpdateIndex] = useState(0);
61
78
  let key = scope.key('item');
@@ -76,38 +93,25 @@ export default function UIListRow(props: UIListRowType) {
76
93
  setUpdateIndex(++updateIndex);
77
94
  };
78
95
 
79
- const Child = () => {
80
- return (
81
- <>
82
- {visible && (
83
- <UIChildren scope={row} crud={row.crud}>
84
- {props.children}
85
- </UIChildren>
86
- )}
87
- </>
88
- );
89
- };
90
-
91
96
  if (!original.click) {
92
97
  return (
93
98
  <View
94
99
  key={key}
95
100
  style={getRowStyle()}
96
- onLayout={checkIfVisible}
97
- ref={viewRef}
101
+ ref={targetRef}
102
+ onLayout={onScroll}
98
103
  >
99
104
  <Child />
100
105
  </View>
101
106
  );
102
107
  }
103
-
104
108
  return (
105
109
  <TouchableHighlight
106
110
  key={key}
107
111
  style={getRowStyle()}
108
- ref={viewRef}
109
112
  underlayColor={'transparent'}
110
- onLayout={checkIfVisible}
113
+ ref={targetRef}
114
+ onLayout={onScroll}
111
115
  onPress={e => {
112
116
  e.stopPropagation();
113
117
  onClick(item);
@@ -1,7 +1,7 @@
1
1
  import { ScrollView, StyleSheet, View } from 'react-native';
2
2
 
3
3
  import UIChildren from '../UIChildren';
4
- import { ChildType, useTheme } from 'react-crud-utils';
4
+ import { ChildType, useTheme, Utils, ViewUtils } from 'react-crud-utils';
5
5
  import { useEffect } from 'react';
6
6
  import { StatusBar } from 'react-native';
7
7
 
@@ -13,11 +13,24 @@ export default function UIView({ scope, children }: ChildType) {
13
13
  StatusBar.setBarStyle('light-content');
14
14
  StatusBar.setBackgroundColor?.(theme.colors.primary);
15
15
  }, []);
16
+
17
+ const onScroll = () => {
18
+ const crud = ViewUtils.getCrud();
19
+
20
+ Utils.each(crud.scroll, s => {
21
+ if (s.onScroll) {
22
+ s.onScroll.call(s);
23
+ }
24
+ });
25
+ };
26
+
16
27
  return (
17
28
  <>
18
29
  {header}
19
30
  <View style={scope.getStyle('container', styles.container)}>
20
31
  <ScrollView
32
+ onScroll={onScroll}
33
+ scrollEventThrottle={16}
21
34
  keyboardShouldPersistTaps="handled"
22
35
  contentContainerStyle={scope.getStyle('contentContainer', {})}
23
36
  style={scope.getStyle('scroll', styles.scroll)}