react-crud-mobile 1.0.439 → 1.0.440

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,135 +1,135 @@
1
- import React, { useState } from 'react';
2
- import { ChildType, Utils } from 'react-crud-utils';
3
- import { StyleSheet, Text, TouchableHighlight, View } from 'react-native';
4
- import UIListRow from './UIListRow';
5
- import UI from '../UI';
6
- import { Ionicons } from '@expo/vector-icons';
7
-
8
- export default function UIList(props: ChildType) {
9
- const scope = props.scope;
10
- const crud = scope.crud;
11
- const original = scope.original;
12
- const cols = Utils.nvl(original.cols, 1);
13
- const rowWidth = Math.floor(100 / cols) + '%';
14
- const items = Utils.nvl(scope.getItems(), []);
15
-
16
- const onClick = (item: any) => {
17
- scope.call('click', { value: item, item, edit: true });
18
- };
19
-
20
- const getStyle = (key: string, extra?: any) => {
21
- return scope.getStyle(key, { ...extra, ...styles[key] });
22
- };
23
-
24
- const getRowStyle = (extra?: any) => {
25
- let row = getStyle('row', {});
26
-
27
- if (cols > 0) {
28
- row.width = rowWidth;
29
- }
30
-
31
- return row;
32
- };
33
-
34
- const getContainerStyle = (extra?: any) => {
35
- let row = getStyle('container', {});
36
-
37
- if (cols > 1) {
38
- row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
39
- }
40
-
41
- return row;
42
- };
43
-
44
- let Empty = () => {
45
- if (!Utils.isEmpty(items)) {
46
- return <></>;
47
- }
48
-
49
- let empty = scope.attr('empty', 'Sem registro');
50
-
51
- if (!empty) {
52
- return <></>;
53
- }
54
-
55
- if (typeof empty === 'string') {
56
- return (
57
- <Text
58
- style={scope.getStyle('empty', {
59
- flex: 1,
60
- fontWeight: 500,
61
- fontSize: 20,
62
- padding: 10,
63
- textAlign: 'center',
64
- justifyContent: 'center',
65
- alignItems: 'center',
66
- })}
67
- >
68
- {empty}
69
- </Text>
70
- );
71
- }
72
-
73
- return <>{empty}</>;
74
- };
75
-
76
- return (
77
- <>
78
- {original.search !== false && (
79
- <UI.Text
80
- placeholder="Pesquisar..."
81
- field="query"
82
- crud={crud}
83
- right={<Ionicons name="search" size={20} color="#888" />}
84
- />
85
- )}
86
-
87
- <View style={getContainerStyle()}>
88
- <Empty />
89
- {items.map((item: any, i: number) => (
90
- <TouchableHighlight
91
- key={`k-${i}`}
92
- style={getRowStyle()}
93
- underlayColor={'transparent'}
94
- onPress={e => {
95
- onClick(item);
96
- }}
97
- >
98
- <View style={getStyle('rowInner')}>
99
- <UIListRow scope={scope} item={item} index={i}>
100
- {props.children}
101
- </UIListRow>
102
- </View>
103
- </TouchableHighlight>
104
- ))}
105
- </View>
106
- </>
107
- );
108
- }
109
-
110
- const styles = StyleSheet.create({
111
- container: {
112
- flex: 1,
113
- width: '100%',
114
- flexDirection: 'row',
115
- flexWrap: 'wrap',
116
- alignItems: 'stretch',
117
- },
118
- row: {
119
- padding: 5,
120
- width: '100%',
121
- },
122
- rowInner: {
123
- flexGrow: 1, // ✅ cresce conforme o conteúdo
124
- justifyContent: 'center',
125
- alignItems: 'center',
126
- backgroundColor: '#f5f5f5',
127
- borderRadius: 8,
128
- padding: 10,
129
- width: '100%',
130
- },
131
- text: {
132
- fontSize: 18,
133
- fontWeight: 'bold',
134
- },
135
- });
1
+ import React, { useState } from 'react';
2
+ import { ChildType, Utils } from 'react-crud-utils';
3
+ import { StyleSheet, Text, TouchableHighlight, View } from 'react-native';
4
+ import UIListRow from './UIListRow';
5
+ import UI from '../UI';
6
+ import { Ionicons } from '@expo/vector-icons';
7
+
8
+ export default function UIList(props: ChildType) {
9
+ const scope = props.scope;
10
+ const crud = scope.crud;
11
+ const original = scope.original;
12
+ const cols = Utils.nvl(original.cols, 1);
13
+ const rowWidth = Math.floor(100 / cols) + '%';
14
+ const items = Utils.nvl(scope.getItems(), []);
15
+
16
+ const onClick = (item: any) => {
17
+ scope.call('click', { value: item, item, edit: true });
18
+ };
19
+
20
+ const getStyle = (key: string, extra?: any) => {
21
+ return scope.getStyle(key, { ...extra, ...styles[key] });
22
+ };
23
+
24
+ const getRowStyle = (extra?: any) => {
25
+ let row = getStyle('row', {});
26
+
27
+ if (cols > 0) {
28
+ row.width = rowWidth;
29
+ }
30
+
31
+ return row;
32
+ };
33
+
34
+ const getContainerStyle = (extra?: any) => {
35
+ let row = getStyle('container', {});
36
+
37
+ if (cols > 1) {
38
+ row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
39
+ }
40
+
41
+ return row;
42
+ };
43
+
44
+ let Empty = () => {
45
+ if (!Utils.isEmpty(items)) {
46
+ return <></>;
47
+ }
48
+
49
+ let empty = scope.attr('empty', 'Sem registro');
50
+
51
+ if (!empty) {
52
+ return <></>;
53
+ }
54
+
55
+ if (typeof empty === 'string') {
56
+ return (
57
+ <Text
58
+ style={scope.getStyle('empty', {
59
+ flex: 1,
60
+ fontWeight: 500,
61
+ fontSize: 20,
62
+ padding: 10,
63
+ textAlign: 'center',
64
+ justifyContent: 'center',
65
+ alignItems: 'center',
66
+ })}
67
+ >
68
+ {empty}
69
+ </Text>
70
+ );
71
+ }
72
+
73
+ return <>{empty}</>;
74
+ };
75
+
76
+ return (
77
+ <>
78
+ {original.search !== false && (
79
+ <UI.Text
80
+ placeholder="Pesquisar..."
81
+ field="query"
82
+ crud={crud}
83
+ right={<Ionicons name="search" size={20} color="#888" />}
84
+ />
85
+ )}
86
+
87
+ <View style={getContainerStyle()}>
88
+ <Empty />
89
+ {items.map((item: any, i: number) => (
90
+ <TouchableHighlight
91
+ key={`k-${i}`}
92
+ style={getRowStyle()}
93
+ underlayColor={'transparent'}
94
+ onPress={e => {
95
+ onClick(item);
96
+ }}
97
+ >
98
+ <View style={getStyle('rowInner')}>
99
+ <UIListRow scope={scope} item={item} index={i}>
100
+ {props.children}
101
+ </UIListRow>
102
+ </View>
103
+ </TouchableHighlight>
104
+ ))}
105
+ </View>
106
+ </>
107
+ );
108
+ }
109
+
110
+ const styles = StyleSheet.create({
111
+ container: {
112
+ flex: 1,
113
+ width: '100%',
114
+ flexDirection: 'row',
115
+ flexWrap: 'wrap',
116
+ alignItems: 'stretch',
117
+ },
118
+ row: {
119
+ padding: 5,
120
+ width: '100%',
121
+ },
122
+ rowInner: {
123
+ flexGrow: 1, // ✅ cresce conforme o conteúdo
124
+ justifyContent: 'center',
125
+ alignItems: 'center',
126
+ backgroundColor: '#f5f5f5',
127
+ borderRadius: 8,
128
+ padding: 10,
129
+ width: '100%',
130
+ },
131
+ text: {
132
+ fontSize: 18,
133
+ fontWeight: 'bold',
134
+ },
135
+ });
@@ -1,32 +1,32 @@
1
- import React, { useState } from 'react';
2
- import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
- import UIChildren from '../UIChildren';
4
-
5
- interface UIListRowType extends ChildType {
6
- item: any;
7
- index: number;
8
- }
9
-
10
- export default function UIListRow(props: UIListRowType) {
11
- const parent = props.scope;
12
- const item = props.item;
13
- const index = props.index;
14
- const name = `${parent.key('row', index)}`;
15
- const row = {
16
- parent,
17
- name,
18
- crud: parent.crud,
19
- index,
20
- type: 'row',
21
- data: item,
22
- };
23
- let [scope] = useState(ScopeUtils.create(row));
24
-
25
- return (
26
- <>
27
- <UIChildren scope={scope} crud={scope.crud}>
28
- {props.children}
29
- </UIChildren>
30
- </>
31
- );
32
- }
1
+ import React, { useState } from 'react';
2
+ import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
+ import UIChildren from '../UIChildren';
4
+
5
+ interface UIListRowType extends ChildType {
6
+ item: any;
7
+ index: number;
8
+ }
9
+
10
+ export default function UIListRow(props: UIListRowType) {
11
+ const parent = props.scope;
12
+ const item = props.item;
13
+ const index = props.index;
14
+ const name = `${parent.key('row', index)}`;
15
+ const row = {
16
+ parent,
17
+ name,
18
+ crud: parent.crud,
19
+ index,
20
+ type: 'row',
21
+ data: item,
22
+ };
23
+ let [scope] = useState(ScopeUtils.create(row));
24
+
25
+ return (
26
+ <>
27
+ <UIChildren scope={scope} crud={scope.crud}>
28
+ {props.children}
29
+ </UIChildren>
30
+ </>
31
+ );
32
+ }
@@ -1,139 +1,139 @@
1
- import { useEffect, useState } from 'react';
2
- import {
3
- ChildType,
4
- CrudUtils,
5
- MethodType,
6
- useTheme,
7
- Utils,
8
- } from 'react-crud-utils';
9
- import {
10
- Text,
11
- TouchableOpacity,
12
- StyleSheet,
13
- Modal,
14
- View,
15
- StatusBar,
16
- SafeAreaView,
17
- ScrollView,
18
- } from 'react-native';
19
- import UIChildren from '../UIChildren';
20
-
21
- export default function UIModal(props: ChildType) {
22
- let [modalVisible, setModalVisible] = useState(false);
23
-
24
- const scope = props.scope;
25
- const label = scope.getLabel();
26
- const theme = useTheme();
27
-
28
- const style = (part: string, extra?: any) => {
29
- let st = { ...styles[part], ...extra };
30
-
31
- return { ...scope.getStyle(part, st) };
32
- };
33
-
34
- const toggle = vis => {
35
- modalVisible = vis;
36
- setModalVisible(modalVisible);
37
- };
38
-
39
- scope.show = (args?: MethodType) => {
40
- let { crud } = args;
41
- let name = scope.getName('modal');
42
- let data = Utils.nvl(args.item, {});
43
- let edit = args.edit === true;
44
- let d = CrudUtils.create('dialog', {
45
- parent: crud,
46
- name,
47
- data,
48
- edit,
49
- scope,
50
- });
51
-
52
- scope.currentDialog = d;
53
-
54
- toggle(true);
55
- };
56
-
57
- scope.hide = (args?: MethodType) => {
58
- scope.currentDialog = null;
59
-
60
- toggle(false);
61
- };
62
-
63
- useEffect(() => {
64
- if (modalVisible) {
65
- StatusBar.setBarStyle('light-content');
66
- StatusBar.setBackgroundColor?.(theme.colors.primary);
67
- } else {
68
- StatusBar.setBarStyle('dark-content');
69
- StatusBar.setBackgroundColor?.('#f5f5f5');
70
- }
71
- }, [modalVisible]);
72
-
73
- if (!scope.currentDialog) {
74
- return <></>;
75
- }
76
-
77
- return (
78
- <Modal
79
- animationType="slide"
80
- transparent={true}
81
- visible={modalVisible}
82
- onRequestClose={() => setModalVisible(false)}
83
- >
84
- <SafeAreaView style={style('modalSafe')}>
85
- <View style={style('modalHeader')}>
86
- <TouchableOpacity
87
- onPress={() => setModalVisible(false)}
88
- style={style('modalCloseButton')}
89
- >
90
- <Text style={style('modalCloseText')}>X</Text>
91
- </TouchableOpacity>
92
- <Text style={style('modalTitle')}>{label}</Text>
93
- </View>
94
- <ScrollView
95
- contentContainerStyle={{ flexGrow: 1 }}
96
- style={style('modalContent')}
97
- >
98
- <View style={{ flex: 1 }}>
99
- <UIChildren scope={scope} crud={scope.currentDialog}>
100
- {props.children}
101
- </UIChildren>
102
- </View>
103
- </ScrollView>
104
- </SafeAreaView>
105
- </Modal>
106
- );
107
- }
108
-
109
- const styles = StyleSheet.create({
110
- modalSafe: {
111
- flex: 1,
112
- backgroundColor: 'primary',
113
- width: '100%',
114
- },
115
- modalHeader: {
116
- flexDirection: 'row',
117
- alignItems: 'center',
118
- padding: 15,
119
- backgroundColor: 'primary',
120
- },
121
- modalCloseButton: {
122
- padding: 10,
123
- },
124
- modalCloseText: {
125
- fontSize: 18,
126
- color: 'white',
127
- },
128
- modalTitle: {
129
- fontSize: 18,
130
- color: 'white',
131
- fontWeight: 'bold',
132
- marginLeft: 10,
133
- },
134
- modalContent: {
135
- flex: 1,
136
- backgroundColor: '#f5f5f5',
137
- padding: 20,
138
- },
139
- });
1
+ import { useEffect, useState } from 'react';
2
+ import {
3
+ ChildType,
4
+ CrudUtils,
5
+ MethodType,
6
+ useTheme,
7
+ Utils,
8
+ } from 'react-crud-utils';
9
+ import {
10
+ Text,
11
+ TouchableOpacity,
12
+ StyleSheet,
13
+ Modal,
14
+ View,
15
+ StatusBar,
16
+ SafeAreaView,
17
+ ScrollView,
18
+ } from 'react-native';
19
+ import UIChildren from '../UIChildren';
20
+
21
+ export default function UIModal(props: ChildType) {
22
+ let [modalVisible, setModalVisible] = useState(false);
23
+
24
+ const scope = props.scope;
25
+ const label = scope.getLabel();
26
+ const theme = useTheme();
27
+
28
+ const style = (part: string, extra?: any) => {
29
+ let st = { ...styles[part], ...extra };
30
+
31
+ return { ...scope.getStyle(part, st) };
32
+ };
33
+
34
+ const toggle = vis => {
35
+ modalVisible = vis;
36
+ setModalVisible(modalVisible);
37
+ };
38
+
39
+ scope.show = (args?: MethodType) => {
40
+ let { crud } = args;
41
+ let name = scope.getName('modal');
42
+ let data = Utils.nvl(args.item, {});
43
+ let edit = args.edit === true;
44
+ let d = CrudUtils.create('dialog', {
45
+ parent: crud,
46
+ name,
47
+ data,
48
+ edit,
49
+ scope,
50
+ });
51
+
52
+ scope.currentDialog = d;
53
+
54
+ toggle(true);
55
+ };
56
+
57
+ scope.hide = (args?: MethodType) => {
58
+ scope.currentDialog = null;
59
+
60
+ toggle(false);
61
+ };
62
+
63
+ useEffect(() => {
64
+ if (modalVisible) {
65
+ StatusBar.setBarStyle('light-content');
66
+ StatusBar.setBackgroundColor?.(theme.colors.primary);
67
+ } else {
68
+ StatusBar.setBarStyle('dark-content');
69
+ StatusBar.setBackgroundColor?.('#f5f5f5');
70
+ }
71
+ }, [modalVisible]);
72
+
73
+ if (!scope.currentDialog) {
74
+ return <></>;
75
+ }
76
+
77
+ return (
78
+ <Modal
79
+ animationType="slide"
80
+ transparent={true}
81
+ visible={modalVisible}
82
+ onRequestClose={() => setModalVisible(false)}
83
+ >
84
+ <SafeAreaView style={style('modalSafe')}>
85
+ <View style={style('modalHeader')}>
86
+ <TouchableOpacity
87
+ onPress={() => setModalVisible(false)}
88
+ style={style('modalCloseButton')}
89
+ >
90
+ <Text style={style('modalCloseText')}>X</Text>
91
+ </TouchableOpacity>
92
+ <Text style={style('modalTitle')}>{label}</Text>
93
+ </View>
94
+ <ScrollView
95
+ contentContainerStyle={{ flexGrow: 1 }}
96
+ style={style('modalContent')}
97
+ >
98
+ <View style={{ flex: 1 }}>
99
+ <UIChildren scope={scope} crud={scope.currentDialog}>
100
+ {props.children}
101
+ </UIChildren>
102
+ </View>
103
+ </ScrollView>
104
+ </SafeAreaView>
105
+ </Modal>
106
+ );
107
+ }
108
+
109
+ const styles = StyleSheet.create({
110
+ modalSafe: {
111
+ flex: 1,
112
+ backgroundColor: 'primary',
113
+ width: '100%',
114
+ },
115
+ modalHeader: {
116
+ flexDirection: 'row',
117
+ alignItems: 'center',
118
+ padding: 15,
119
+ backgroundColor: 'primary',
120
+ },
121
+ modalCloseButton: {
122
+ padding: 10,
123
+ },
124
+ modalCloseText: {
125
+ fontSize: 18,
126
+ color: 'white',
127
+ },
128
+ modalTitle: {
129
+ fontSize: 18,
130
+ color: 'white',
131
+ fontWeight: 'bold',
132
+ marginLeft: 10,
133
+ },
134
+ modalContent: {
135
+ flex: 1,
136
+ backgroundColor: '#f5f5f5',
137
+ padding: 20,
138
+ },
139
+ });