react-crud-mobile 1.3.52 → 1.3.53

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.
@@ -1,123 +1,123 @@
1
- import React, { useRef, useState } from 'react';
2
- import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
- import UIChildren from '../UIChildren';
4
- import { StyleSheet, TouchableHighlight, View } from 'react-native';
5
- import { useIsVisible } from '../../hooks/useIsVisible';
6
-
7
- interface UIListRowType extends ChildType {
8
- item: any;
9
- index: number;
10
- }
11
-
12
- export default function UIListRow(props: UIListRowType) {
13
- const scope = props.scope;
14
- const index = props.index;
15
- const original = scope.original;
16
- const item = props.item;
17
- const cols = scope.getPart('cols', undefined, -1);
18
- const rowWidth = Math.floor(100 / cols) + '%';
19
- const styles = { repeat: stylesRepeat, list: stylesList }?.[original.type];
20
- const name = `${scope.key('row', index, '')}`;
21
- const [row] = useState(
22
- ScopeUtils.create({
23
- ...original,
24
- parent: scope,
25
- name,
26
- crud: scope.crud,
27
- index,
28
- type: 'row',
29
- data: item,
30
- })
31
- );
32
-
33
- const targetRef = useRef(null);
34
- const isVisible = useIsVisible(targetRef, row);
35
-
36
- const onClick = (item: any) => {
37
- row.call('click', { value: item, item, edit: true, index });
38
- };
39
-
40
- const Child = () => {
41
- if (!isVisible && original.useIsInView && !row.visible && index > 20) {
42
- return <></>;
43
- }
44
- return (
45
- <>
46
- <UIChildren scope={row} crud={row.crud}>
47
- {props.children}
48
- </UIChildren>
49
- </>
50
- );
51
- };
52
-
53
- const ListItem = () => {
54
- let [updateIndex, setUpdateIndex] = useState(0);
55
- let key = scope.key('item');
56
-
57
- const getRowStyle = () => {
58
- let css = row.getStyle('row', { ...styles.row, minHeight: 40 });
59
-
60
- if (cols > 0) {
61
- css.width = rowWidth;
62
- }
63
-
64
- return css;
65
- };
66
-
67
- row.update = () => {
68
- scope.updateIndex = scope.updateIndex + 1;
69
-
70
- setUpdateIndex(++updateIndex);
71
- };
72
-
73
- let renderedRow = row.getPart('renderedItem', undefined, true);
74
-
75
- if (renderedRow === false) {
76
- return <></>;
77
- }
78
-
79
- if (!original.click) {
80
- return (
81
- <View key={key} style={getRowStyle()} ref={targetRef}>
82
- <Child />
83
- </View>
84
- );
85
- }
86
- return (
87
- <TouchableHighlight
88
- key={key}
89
- style={getRowStyle()}
90
- underlayColor={'transparent'}
91
- ref={targetRef}
92
- onPress={e => {
93
- e.stopPropagation();
94
- onClick(item);
95
- }}
96
- >
97
- <Child />
98
- </TouchableHighlight>
99
- );
100
- };
101
-
102
- return <ListItem />;
103
- }
104
-
105
- const stylesList = StyleSheet.create({
106
- row: {
107
- padding: 5,
108
- margin: 0,
109
- width: '100%',
110
- backgroundColor: 'background',
111
- gap: 10,
112
- borderRadius: 8,
113
- justifyContent: 'center',
114
- },
115
- });
116
-
117
- const stylesRepeat = StyleSheet.create({
118
- row: {
119
- padding: 0,
120
- width: '100%',
121
- justifyContent: 'center',
122
- },
123
- });
1
+ import React, { useRef, useState } from 'react';
2
+ import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
+ import UIChildren from '../UIChildren';
4
+ import { StyleSheet, TouchableHighlight, View } from 'react-native';
5
+ import { useIsVisible } from '../../hooks/useIsVisible';
6
+
7
+ interface UIListRowType extends ChildType {
8
+ item: any;
9
+ index: number;
10
+ }
11
+
12
+ export default function UIListRow(props: UIListRowType) {
13
+ const scope = props.scope;
14
+ const index = props.index;
15
+ const original = scope.original;
16
+ const item = props.item;
17
+ const cols = scope.getPart('cols', undefined, -1);
18
+ const rowWidth = Math.floor(100 / cols) + '%';
19
+ const styles = { repeat: stylesRepeat, list: stylesList }?.[original.type];
20
+ const name = `${scope.key('row', index, '')}`;
21
+ const [row] = useState(
22
+ ScopeUtils.create({
23
+ ...original,
24
+ parent: scope,
25
+ name,
26
+ crud: scope.crud,
27
+ index,
28
+ type: 'row',
29
+ data: item,
30
+ })
31
+ );
32
+
33
+ const targetRef = useRef(null);
34
+ const isVisible = useIsVisible(targetRef, row);
35
+
36
+ const onClick = (item: any) => {
37
+ row.call('click', { value: item, item, edit: true, index });
38
+ };
39
+
40
+ const Child = () => {
41
+ if (!isVisible && original.useIsInView && !row.visible && index > 20) {
42
+ return <></>;
43
+ }
44
+ return (
45
+ <>
46
+ <UIChildren scope={row} crud={row.crud}>
47
+ {props.children}
48
+ </UIChildren>
49
+ </>
50
+ );
51
+ };
52
+
53
+ const ListItem = () => {
54
+ let [updateIndex, setUpdateIndex] = useState(0);
55
+ let key = scope.key('item');
56
+
57
+ const getRowStyle = () => {
58
+ let css = row.getStyle('row', { ...styles.row, minHeight: 40 });
59
+
60
+ if (cols > 0) {
61
+ css.width = rowWidth;
62
+ }
63
+
64
+ return css;
65
+ };
66
+
67
+ row.update = () => {
68
+ scope.updateIndex = scope.updateIndex + 1;
69
+
70
+ setUpdateIndex(++updateIndex);
71
+ };
72
+
73
+ let renderedRow = row.getPart('renderedItem', undefined, true);
74
+
75
+ if (renderedRow === false) {
76
+ return <></>;
77
+ }
78
+
79
+ if (!original.click) {
80
+ return (
81
+ <View key={key} style={getRowStyle()} ref={targetRef}>
82
+ <Child />
83
+ </View>
84
+ );
85
+ }
86
+ return (
87
+ <TouchableHighlight
88
+ key={key}
89
+ style={getRowStyle()}
90
+ underlayColor={'transparent'}
91
+ ref={targetRef}
92
+ onPress={e => {
93
+ e.stopPropagation();
94
+ onClick(item);
95
+ }}
96
+ >
97
+ <Child />
98
+ </TouchableHighlight>
99
+ );
100
+ };
101
+
102
+ return <ListItem />;
103
+ }
104
+
105
+ const stylesList = StyleSheet.create({
106
+ row: {
107
+ padding: 5,
108
+ margin: 0,
109
+ width: '100%',
110
+ backgroundColor: 'background',
111
+ gap: 10,
112
+ borderRadius: 8,
113
+ justifyContent: 'center',
114
+ },
115
+ });
116
+
117
+ const stylesRepeat = StyleSheet.create({
118
+ row: {
119
+ padding: 0,
120
+ width: '100%',
121
+ justifyContent: 'center',
122
+ },
123
+ });
@@ -1,206 +1,206 @@
1
- import { useRef, useState } from 'react';
2
- import {
3
- ChildType,
4
- ComponentUtils,
5
- CrudUtils,
6
- MethodType,
7
- Utils,
8
- ViewUtils,
9
- } from 'react-crud-utils';
10
- import {
11
- Text,
12
- TouchableOpacity,
13
- StyleSheet,
14
- Modal,
15
- View,
16
- SafeAreaView,
17
- ScrollView,
18
- } from 'react-native';
19
- import UIChildren from '../UIChildren';
20
- import Ionicons from '@expo/vector-icons/Ionicons';
21
- import UIToast from './UIToast';
22
-
23
- export default function UIModal(props: ChildType) {
24
- let [modalVisible, setModalVisible] = useState(false);
25
- let [index, setIndex] = useState(0);
26
- let main = ViewUtils.getCrud('view');
27
- //v3
28
-
29
- const scope = props.scope;
30
- const label = scope.getLabel();
31
- const theme = scope.getTheme();
32
- const headerStyle = Utils.nvl(theme.styles?.defaults?.header, {});
33
- const scrollRef = useRef(null);
34
-
35
- const style = (part: string, extra?: any) => {
36
- let st = { ...styles[part], ...extra };
37
-
38
- return { ...scope.getStyle(part, st) };
39
- };
40
-
41
- const onClose = () => {
42
- scope.close({ scope, crud: scope.currentDialog, event: {} });
43
- };
44
-
45
- const toggle = vis => {
46
- modalVisible = vis;
47
- setModalVisible(modalVisible);
48
- };
49
-
50
- scope.update = () => {
51
- setIndex(++index);
52
- };
53
-
54
- scope.dialogShow = (args?: MethodType) => {
55
- let { crud } = args;
56
- let name = scope.getName('modal');
57
- let edit = args.edit === true;
58
- let def: any = {};
59
- let rowItem = null;
60
-
61
- if (crud.is('row')) {
62
- def.parent = crud.parent.parent;
63
- def.search = crud.parent;
64
-
65
- rowItem = crud.data;
66
- } else if (crud.is('search')) {
67
- def.parent = crud.parent;
68
- def.search = crud;
69
- }
70
-
71
- let data = Utils.nvl(args.item, rowItem, {});
72
-
73
- let d = CrudUtils.create('dialog', {
74
- parent: crud,
75
- root: crud,
76
- name,
77
- dialog: main.dialog,
78
- data,
79
- edit,
80
- scope,
81
- ...def,
82
- });
83
-
84
- main.dialog = d;
85
-
86
- scope.currentDialog = d;
87
-
88
- toggle(true);
89
- scope.update();
90
- };
91
-
92
- scope.dialogHide = (args?: MethodType) => {
93
- let old = scope.currentDialog;
94
-
95
- main.dialog = Utils.nvl(old.dialog, null);
96
- scope.currentDialog = null;
97
-
98
- toggle(false);
99
-
100
- if (main.dialog?.scope) {
101
- main.dialog.scope.update();
102
- }
103
- scope.update();
104
- };
105
-
106
- let curr = scope.currentDialog;
107
-
108
- if (!curr) {
109
- return <></>;
110
- }
111
-
112
- if (curr.uuid !== main.dialog?.uuid) {
113
- return <></>;
114
- }
115
-
116
- const headerRight = ComponentUtils.getDefine(props, 'header', 'right');
117
- const bottom = ComponentUtils.getDefine(props, 'bottom');
118
-
119
- scope.put('scrollRef', scrollRef);
120
-
121
- ComponentUtils.setViewScope(scope);
122
-
123
- let color = Utils.nvl(headerStyle.color, 'white');
124
- let defaults = { color };
125
- let key = `${scope.currentDialog.name}-${index}`;
126
-
127
- return (
128
- <Modal
129
- key={key}
130
- animationType="slide"
131
- transparent={true}
132
- visible={modalVisible}
133
- onRequestClose={onClose}
134
- >
135
- <SafeAreaView style={style('modalTop')} />
136
- <SafeAreaView style={style('modalSafe')}>
137
- <View style={scope.getStyle('header', headerStyle)}>
138
- <TouchableOpacity onPress={onClose} style={style('modalCloseButton')}>
139
- <Ionicons
140
- name="chevron-back-outline"
141
- size={24}
142
- color={color}
143
- style={style('modalCloseText', defaults)}
144
- />
145
- </TouchableOpacity>
146
- <Text style={style('modalTitle', defaults)}>{label}</Text>
147
- {!Utils.isEmpty(headerRight) && (
148
- <UIChildren scope={scope} crud={scope.currentDialog} transient>
149
- {headerRight}
150
- </UIChildren>
151
- )}
152
- </View>
153
- <ScrollView
154
- contentContainerStyle={{ flexGrow: 1, paddingBottom: 50 }}
155
- style={style('modalContent')}
156
- nestedScrollEnabled={true}
157
- ref={scrollRef}
158
- >
159
- <View
160
- style={{
161
- flex: 1,
162
- paddingLeft: 15,
163
- paddingRight: 15,
164
- paddingTop: 10,
165
- paddingBottom: 10,
166
- }}
167
- >
168
- <UIChildren scope={scope} crud={scope.currentDialog}>
169
- {props.children}
170
- </UIChildren>
171
- </View>
172
- </ScrollView>
173
- {bottom}
174
- </SafeAreaView>
175
- <UIToast />
176
- </Modal>
177
- );
178
- }
179
-
180
- const styles = StyleSheet.create({
181
- modalTop: {
182
- backgroundColor: 'primary',
183
- width: '100%',
184
- },
185
- modalSafe: {
186
- flex: 1,
187
- width: '100%',
188
- backgroundColor: 'background',
189
- },
190
- modalCloseButton: {
191
- padding: 10,
192
- },
193
- modalCloseText: {
194
- fontSize: 18,
195
- color: 'white',
196
- },
197
- modalTitle: {
198
- fontSize: 18,
199
- fontWeight: 'bold',
200
- marginLeft: 10,
201
- },
202
- modalContent: {
203
- flex: 1,
204
- backgroundColor: 'background',
205
- },
206
- });
1
+ import { useRef, useState } from 'react';
2
+ import {
3
+ ChildType,
4
+ ComponentUtils,
5
+ CrudUtils,
6
+ MethodType,
7
+ Utils,
8
+ ViewUtils,
9
+ } from 'react-crud-utils';
10
+ import {
11
+ Text,
12
+ TouchableOpacity,
13
+ StyleSheet,
14
+ Modal,
15
+ View,
16
+ SafeAreaView,
17
+ ScrollView,
18
+ } from 'react-native';
19
+ import UIChildren from '../UIChildren';
20
+ import Ionicons from '@expo/vector-icons/Ionicons';
21
+ import UIToast from './UIToast';
22
+
23
+ export default function UIModal(props: ChildType) {
24
+ let [modalVisible, setModalVisible] = useState(false);
25
+ let [index, setIndex] = useState(0);
26
+ let main = ViewUtils.getCrud('view');
27
+ //v3
28
+
29
+ const scope = props.scope;
30
+ const label = scope.getLabel();
31
+ const theme = scope.getTheme();
32
+ const headerStyle = Utils.nvl(theme.styles?.defaults?.header, {});
33
+ const scrollRef = useRef(null);
34
+
35
+ const style = (part: string, extra?: any) => {
36
+ let st = { ...styles[part], ...extra };
37
+
38
+ return { ...scope.getStyle(part, st) };
39
+ };
40
+
41
+ const onClose = () => {
42
+ scope.close({ scope, crud: scope.currentDialog, event: {} });
43
+ };
44
+
45
+ const toggle = vis => {
46
+ modalVisible = vis;
47
+ setModalVisible(modalVisible);
48
+ };
49
+
50
+ scope.update = () => {
51
+ setIndex(++index);
52
+ };
53
+
54
+ scope.dialogShow = (args?: MethodType) => {
55
+ let { crud } = args;
56
+ let name = scope.getName('modal');
57
+ let edit = args.edit === true;
58
+ let def: any = {};
59
+ let rowItem = null;
60
+
61
+ if (crud.is('row')) {
62
+ def.parent = crud.parent.parent;
63
+ def.search = crud.parent;
64
+
65
+ rowItem = crud.data;
66
+ } else if (crud.is('search')) {
67
+ def.parent = crud.parent;
68
+ def.search = crud;
69
+ }
70
+
71
+ let data = Utils.nvl(args.item, rowItem, {});
72
+
73
+ let d = CrudUtils.create('dialog', {
74
+ parent: crud,
75
+ root: crud,
76
+ name,
77
+ dialog: main.dialog,
78
+ data,
79
+ edit,
80
+ scope,
81
+ ...def,
82
+ });
83
+
84
+ main.dialog = d;
85
+
86
+ scope.currentDialog = d;
87
+
88
+ toggle(true);
89
+ scope.update();
90
+ };
91
+
92
+ scope.dialogHide = (args?: MethodType) => {
93
+ let old = scope.currentDialog;
94
+
95
+ main.dialog = Utils.nvl(old.dialog, null);
96
+ scope.currentDialog = null;
97
+
98
+ toggle(false);
99
+
100
+ if (main.dialog?.scope) {
101
+ main.dialog.scope.update();
102
+ }
103
+ scope.update();
104
+ };
105
+
106
+ let curr = scope.currentDialog;
107
+
108
+ if (!curr) {
109
+ return <></>;
110
+ }
111
+
112
+ if (curr.uuid !== main.dialog?.uuid) {
113
+ return <></>;
114
+ }
115
+
116
+ const headerRight = ComponentUtils.getDefine(props, 'header', 'right');
117
+ const bottom = ComponentUtils.getDefine(props, 'bottom');
118
+
119
+ scope.put('scrollRef', scrollRef);
120
+
121
+ ComponentUtils.setViewScope(scope);
122
+
123
+ let color = Utils.nvl(headerStyle.color, 'white');
124
+ let defaults = { color };
125
+ let key = `${scope.currentDialog.name}-${index}`;
126
+
127
+ return (
128
+ <Modal
129
+ key={key}
130
+ animationType="slide"
131
+ transparent={true}
132
+ visible={modalVisible}
133
+ onRequestClose={onClose}
134
+ >
135
+ <SafeAreaView style={style('modalTop')} />
136
+ <SafeAreaView style={style('modalSafe')}>
137
+ <View style={scope.getStyle('header', headerStyle)}>
138
+ <TouchableOpacity onPress={onClose} style={style('modalCloseButton')}>
139
+ <Ionicons
140
+ name="chevron-back-outline"
141
+ size={24}
142
+ color={color}
143
+ style={style('modalCloseText', defaults)}
144
+ />
145
+ </TouchableOpacity>
146
+ <Text style={style('modalTitle', defaults)}>{label}</Text>
147
+ {!Utils.isEmpty(headerRight) && (
148
+ <UIChildren scope={scope} crud={scope.currentDialog} transient>
149
+ {headerRight}
150
+ </UIChildren>
151
+ )}
152
+ </View>
153
+ <ScrollView
154
+ contentContainerStyle={{ flexGrow: 1, paddingBottom: 50 }}
155
+ style={style('modalContent')}
156
+ nestedScrollEnabled={true}
157
+ ref={scrollRef}
158
+ >
159
+ <View
160
+ style={{
161
+ flex: 1,
162
+ paddingLeft: 15,
163
+ paddingRight: 15,
164
+ paddingTop: 10,
165
+ paddingBottom: 10,
166
+ }}
167
+ >
168
+ <UIChildren scope={scope} crud={scope.currentDialog}>
169
+ {props.children}
170
+ </UIChildren>
171
+ </View>
172
+ </ScrollView>
173
+ {bottom}
174
+ </SafeAreaView>
175
+ <UIToast />
176
+ </Modal>
177
+ );
178
+ }
179
+
180
+ const styles = StyleSheet.create({
181
+ modalTop: {
182
+ backgroundColor: 'primary',
183
+ width: '100%',
184
+ },
185
+ modalSafe: {
186
+ flex: 1,
187
+ width: '100%',
188
+ backgroundColor: 'background',
189
+ },
190
+ modalCloseButton: {
191
+ padding: 10,
192
+ },
193
+ modalCloseText: {
194
+ fontSize: 18,
195
+ color: 'white',
196
+ },
197
+ modalTitle: {
198
+ fontSize: 18,
199
+ fontWeight: 'bold',
200
+ marginLeft: 10,
201
+ },
202
+ modalContent: {
203
+ flex: 1,
204
+ backgroundColor: 'background',
205
+ },
206
+ });