react-crud-mobile 1.0.533 → 1.0.535

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,165 +1,173 @@
1
- import { useEffect, useState } from 'react';
2
- import {
3
- ChildType,
4
- CrudUtils,
5
- MethodType,
6
- useTheme,
7
- Utils,
8
- ViewUtils,
9
- } from 'react-crud-utils';
10
- import {
11
- Text,
12
- TouchableOpacity,
13
- StyleSheet,
14
- Modal,
15
- View,
16
- StatusBar,
17
- SafeAreaView,
18
- ScrollView,
19
- } from 'react-native';
20
- import UIChildren from '../UIChildren';
21
-
22
- export default function UIModal(props: ChildType) {
23
- let [modalVisible, setModalVisible] = useState(false);
24
- let [index, setIndex] = useState(0);
25
- let main = ViewUtils.getCrud('view');
26
-
27
- const scope = props.scope;
28
- const label = scope.getLabel();
29
- const theme = useTheme();
30
-
31
- const style = (part: string, extra?: any) => {
32
- let st = { ...styles[part], ...extra };
33
-
34
- return { ...scope.getStyle(part, st) };
35
- };
36
-
37
- const onClose = () => {
38
- scope.close({ scope, crud: scope.currentDialog, event: {} });
39
- };
40
-
41
- const toggle = vis => {
42
- modalVisible = vis;
43
- setModalVisible(modalVisible);
44
- };
45
-
46
- scope.update = () => {
47
- setIndex(++index);
48
- };
49
- scope.show = (args?: MethodType) => {
50
- let { crud } = args;
51
- let name = scope.getName('modal');
52
- let data = Utils.nvl(args.item, {});
53
- let edit = args.edit === true;
54
- let def: any = {};
55
-
56
- if (crud.is('search')) {
57
- def.parent = crud.parent;
58
- def.search = crud;
59
- }
60
-
61
- let d = CrudUtils.create('dialog', {
62
- parent: crud,
63
- name,
64
- dialog: main.dialog,
65
- data,
66
- edit,
67
- scope,
68
- ...def,
69
- });
70
-
71
- main.dialog = d;
72
-
73
- scope.currentDialog = d;
74
-
75
- toggle(true);
76
- };
77
-
78
- scope.hide = (args?: MethodType) => {
79
- let old = scope.currentDialog;
80
-
81
- main.dialog = Utils.nvl(old.dialog, null);
82
- scope.currentDialog = null;
83
-
84
- toggle(false);
85
-
86
- if (main.dialog) {
87
- main.dialog.update();
88
- }
89
- };
90
-
91
- useEffect(() => {
92
- StatusBar.setBarStyle('light-content');
93
- StatusBar.setBackgroundColor?.(theme.colors.primary);
94
- }, [modalVisible]);
95
-
96
- let curr = scope.currentDialog;
97
-
98
- if (!curr) {
99
- return <></>;
100
- }
101
-
102
- if (curr.uuid !== main.dialog.uuid) {
103
- return <></>;
104
- }
105
-
106
- return (
107
- <Modal
108
- animationType="slide"
109
- transparent={true}
110
- visible={modalVisible}
111
- onRequestClose={onClose}
112
- >
113
- <SafeAreaView style={style('modalSafe')}>
114
- <View style={style('modalHeader')}>
115
- <TouchableOpacity onPress={onClose} style={style('modalCloseButton')}>
116
- <Text style={style('modalCloseText')}>X</Text>
117
- </TouchableOpacity>
118
- <Text style={style('modalTitle')}>{label}</Text>
119
- </View>
120
- <ScrollView
121
- contentContainerStyle={{ flexGrow: 1 }}
122
- style={style('modalContent')}
123
- >
124
- <View style={{ flex: 1 }}>
125
- <UIChildren scope={scope} crud={scope.currentDialog}>
126
- {props.children}
127
- </UIChildren>
128
- </View>
129
- </ScrollView>
130
- </SafeAreaView>
131
- </Modal>
132
- );
133
- }
134
-
135
- const styles = StyleSheet.create({
136
- modalSafe: {
137
- flex: 1,
138
- backgroundColor: 'primary',
139
- width: '100%',
140
- },
141
- modalHeader: {
142
- flexDirection: 'row',
143
- alignItems: 'center',
144
- padding: 15,
145
- backgroundColor: 'primary',
146
- },
147
- modalCloseButton: {
148
- padding: 10,
149
- },
150
- modalCloseText: {
151
- fontSize: 18,
152
- color: 'white',
153
- },
154
- modalTitle: {
155
- fontSize: 18,
156
- color: 'white',
157
- fontWeight: 'bold',
158
- marginLeft: 10,
159
- },
160
- modalContent: {
161
- flex: 1,
162
- backgroundColor: '#f5f5f5',
163
- padding: 20,
164
- },
165
- });
1
+ import { useEffect, useState } from 'react';
2
+ import {
3
+ ChildType,
4
+ ComponentUtils,
5
+ CrudUtils,
6
+ MethodType,
7
+ useTheme,
8
+ Utils,
9
+ ViewUtils,
10
+ } from 'react-crud-utils';
11
+ import {
12
+ Text,
13
+ TouchableOpacity,
14
+ StyleSheet,
15
+ Modal,
16
+ View,
17
+ StatusBar,
18
+ SafeAreaView,
19
+ ScrollView,
20
+ } from 'react-native';
21
+ import UIChildren from '../UIChildren';
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
+
28
+ const scope = props.scope;
29
+ const label = scope.getLabel();
30
+ const theme = useTheme();
31
+
32
+ const style = (part: string, extra?: any) => {
33
+ let st = { ...styles[part], ...extra };
34
+
35
+ return { ...scope.getStyle(part, st) };
36
+ };
37
+
38
+ const onClose = () => {
39
+ scope.close({ scope, crud: scope.currentDialog, event: {} });
40
+ };
41
+
42
+ const toggle = vis => {
43
+ modalVisible = vis;
44
+ setModalVisible(modalVisible);
45
+ };
46
+
47
+ scope.update = () => {
48
+ setIndex(++index);
49
+ };
50
+ scope.show = (args?: MethodType) => {
51
+ let { crud } = args;
52
+ let name = scope.getName('modal');
53
+ let data = Utils.nvl(args.item, {});
54
+ let edit = args.edit === true;
55
+ let def: any = {};
56
+
57
+ if (crud.is('search')) {
58
+ def.parent = crud.parent;
59
+ def.search = crud;
60
+ }
61
+
62
+ let d = CrudUtils.create('dialog', {
63
+ parent: crud,
64
+ name,
65
+ dialog: main.dialog,
66
+ data,
67
+ edit,
68
+ scope,
69
+ ...def,
70
+ });
71
+
72
+ main.dialog = d;
73
+
74
+ scope.currentDialog = d;
75
+
76
+ toggle(true);
77
+ };
78
+
79
+ scope.hide = (args?: MethodType) => {
80
+ let old = scope.currentDialog;
81
+
82
+ main.dialog = Utils.nvl(old.dialog, null);
83
+ scope.currentDialog = null;
84
+
85
+ toggle(false);
86
+
87
+ if (main.dialog?.scope) {
88
+ main.dialog.scope.update();
89
+ }
90
+ };
91
+
92
+ useEffect(() => {
93
+ StatusBar.setBarStyle('light-content');
94
+ StatusBar.setBackgroundColor?.(theme.colors.primary);
95
+ }, [modalVisible]);
96
+
97
+ let curr = scope.currentDialog;
98
+
99
+ if (!curr) {
100
+ return <></>;
101
+ }
102
+
103
+ if (curr.uuid !== main.dialog.uuid) {
104
+ return <></>;
105
+ }
106
+
107
+ const headerRight = ComponentUtils.getDefine(props, 'header', 'right');
108
+
109
+ return (
110
+ <Modal
111
+ animationType="slide"
112
+ transparent={true}
113
+ visible={modalVisible}
114
+ onRequestClose={onClose}
115
+ >
116
+ <SafeAreaView style={style('modalSafe')}>
117
+ <View style={style('modalHeader')}>
118
+ <TouchableOpacity onPress={onClose} style={style('modalCloseButton')}>
119
+ <Text style={style('modalCloseText')}>X</Text>
120
+ </TouchableOpacity>
121
+ <Text style={style('modalTitle')}>{label}</Text>
122
+ {!Utils.isEmpty(headerRight) && (
123
+ <UIChildren scope={scope} crud={scope.currentDialog}>
124
+ {headerRight}
125
+ </UIChildren>
126
+ )}
127
+ </View>
128
+ <ScrollView
129
+ contentContainerStyle={{ flexGrow: 1 }}
130
+ style={style('modalContent')}
131
+ >
132
+ <View style={{ flex: 1 }}>
133
+ <UIChildren scope={scope} crud={scope.currentDialog}>
134
+ {props.children}
135
+ </UIChildren>
136
+ </View>
137
+ </ScrollView>
138
+ </SafeAreaView>
139
+ </Modal>
140
+ );
141
+ }
142
+
143
+ const styles = StyleSheet.create({
144
+ modalSafe: {
145
+ flex: 1,
146
+ backgroundColor: 'primary',
147
+ width: '100%',
148
+ },
149
+ modalHeader: {
150
+ flexDirection: 'row',
151
+ alignItems: 'center',
152
+ padding: 15,
153
+ backgroundColor: 'primary',
154
+ },
155
+ modalCloseButton: {
156
+ padding: 10,
157
+ },
158
+ modalCloseText: {
159
+ fontSize: 18,
160
+ color: 'white',
161
+ },
162
+ modalTitle: {
163
+ fontSize: 18,
164
+ color: 'white',
165
+ fontWeight: 'bold',
166
+ marginLeft: 10,
167
+ },
168
+ modalContent: {
169
+ flex: 1,
170
+ backgroundColor: '#f5f5f5',
171
+ padding: 20,
172
+ },
173
+ });
@@ -1,97 +1,97 @@
1
- import { Ionicons } from '@expo/vector-icons';
2
- import { useState } from 'react';
3
- import { ChildType, Utils } from 'react-crud-utils';
4
- import { Text, TouchableHighlight, View } from 'react-native';
5
-
6
- export default function UIQuantity(props: ChildType) {
7
- const scope = props.scope;
8
- const element = scope.original;
9
-
10
- let [index, setIndex] = useState(0);
11
-
12
- const value = scope.getValue(0);
13
-
14
- let color = element.color;
15
-
16
- if (!color) color = 'primary';
17
-
18
- const btn = {
19
- padding: 10,
20
- alignItems: 'center',
21
- height: 44,
22
- width: 44,
23
- textAlign: 'center',
24
- verticalAling: 'middle',
25
- borderRadius: 24,
26
- backgroundColor: color,
27
- color: '#ffffff',
28
- justifyContent: 'center',
29
- };
30
-
31
- const styles: any = {
32
- buttonLabel: {
33
- color: '#ffffff',
34
- fontWeight: '500',
35
- fontSize: 16,
36
- },
37
- value: {
38
- flex: 1,
39
- flexDirection: 'row',
40
- textAlign: 'center',
41
- },
42
- buttonInner: {
43
- flexDirection: 'row',
44
- alignItems: 'center',
45
- justifyContent: 'center',
46
- },
47
- buttonIcon: {
48
- color: '#fff',
49
- fontSize: 18,
50
- },
51
- button: btn,
52
- addButton: {
53
- ...btn,
54
- },
55
- delButton: {
56
- ...btn,
57
- },
58
- };
59
-
60
- const change = (val: number) => {
61
- scope.changeValue(value + val);
62
- setIndex(++index);
63
- };
64
-
65
- const onClickAdd = () => {
66
- change(1);
67
- };
68
-
69
- const onClickDel = () => {
70
- change(-1);
71
- };
72
-
73
- const style = (part: string, extra?: any) => {
74
- let s = { ...styles[part], ...extra };
75
- return scope.getStyle(part, s);
76
- };
77
-
78
- return (
79
- <>
80
- <TouchableHighlight
81
- underlayColor={'transparent'}
82
- onPress={onClickDel}
83
- style={style('delButton')}
84
- >
85
- <Ionicons size={30} style={style('buttonIcon')} name="remove" />
86
- </TouchableHighlight>
87
- <Text style={style('value')}>{Utils.nvl(value, 0)}</Text>
88
- <TouchableHighlight
89
- underlayColor={'transparent'}
90
- onPress={onClickAdd}
91
- style={style('addButton')}
92
- >
93
- <Ionicons size={30} style={style('buttonIcon')} name="add" />
94
- </TouchableHighlight>
95
- </>
96
- );
97
- }
1
+ import { Ionicons } from '@expo/vector-icons';
2
+ import { useState } from 'react';
3
+ import { ChildType, Utils } from 'react-crud-utils';
4
+ import { Text, TouchableHighlight, View } from 'react-native';
5
+
6
+ export default function UIQuantity(props: ChildType) {
7
+ const scope = props.scope;
8
+ const element = scope.original;
9
+
10
+ let [index, setIndex] = useState(0);
11
+
12
+ const value = scope.getValue(0);
13
+
14
+ let color = element.color;
15
+
16
+ if (!color) color = 'primary';
17
+
18
+ const btn = {
19
+ padding: 10,
20
+ alignItems: 'center',
21
+ height: 44,
22
+ width: 44,
23
+ textAlign: 'center',
24
+ verticalAling: 'middle',
25
+ borderRadius: 24,
26
+ backgroundColor: color,
27
+ color: '#ffffff',
28
+ justifyContent: 'center',
29
+ };
30
+
31
+ const styles: any = {
32
+ buttonLabel: {
33
+ color: '#ffffff',
34
+ fontWeight: '500',
35
+ fontSize: 16,
36
+ },
37
+ value: {
38
+ flex: 1,
39
+ flexDirection: 'row',
40
+ textAlign: 'center',
41
+ },
42
+ buttonInner: {
43
+ flexDirection: 'row',
44
+ alignItems: 'center',
45
+ justifyContent: 'center',
46
+ },
47
+ buttonIcon: {
48
+ color: '#fff',
49
+ fontSize: 18,
50
+ },
51
+ button: btn,
52
+ addButton: {
53
+ ...btn,
54
+ },
55
+ delButton: {
56
+ ...btn,
57
+ },
58
+ };
59
+
60
+ const change = (val: number) => {
61
+ scope.changeValue(value + val);
62
+ setIndex(++index);
63
+ };
64
+
65
+ const onClickAdd = () => {
66
+ change(1);
67
+ };
68
+
69
+ const onClickDel = () => {
70
+ change(-1);
71
+ };
72
+
73
+ const style = (part: string, extra?: any) => {
74
+ let s = { ...styles[part], ...extra };
75
+ return scope.getStyle(part, s);
76
+ };
77
+
78
+ return (
79
+ <>
80
+ <TouchableHighlight
81
+ underlayColor={'transparent'}
82
+ onPress={onClickDel}
83
+ style={style('delButton')}
84
+ >
85
+ <Ionicons size={30} style={style('buttonIcon')} name="remove" />
86
+ </TouchableHighlight>
87
+ <Text style={style('value')}>{Utils.nvl(value, 0)}</Text>
88
+ <TouchableHighlight
89
+ underlayColor={'transparent'}
90
+ onPress={onClickAdd}
91
+ style={style('addButton')}
92
+ >
93
+ <Ionicons size={30} style={style('buttonIcon')} name="add" />
94
+ </TouchableHighlight>
95
+ </>
96
+ );
97
+ }