react-crud-mobile 1.0.592 → 1.0.596

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.
@@ -10,30 +10,15 @@ export default function UIList(props: ChildType) {
10
10
  const crud = scope.crud;
11
11
  const original = scope.original;
12
12
  const cols = Utils.nvl(original.cols, 1);
13
- const rowWidth = Math.floor(100 / cols) + '%';
14
13
  const items = Utils.nvl(scope.getItems(), []);
15
14
  const styles = { repeat: stylesRepeat, list: stylesList }?.[original.type];
16
15
  const add = ComponentUtils.getDefine(props, 'add');
17
16
  const hideAddWhenEmpty = original.hideAddWhenEmpty;
18
17
 
19
- const onClick = (item: any) => {
20
- scope.call('click', { value: item, item, edit: true });
21
- };
22
-
23
18
  const getStyle = (key: string, extra?: any) => {
24
19
  return scope.getStyle(key, { ...extra, ...styles[key] });
25
20
  };
26
21
 
27
- const getRowStyle = (extra?: any) => {
28
- let row = getStyle('row', {});
29
-
30
- if (cols > 0) {
31
- row.width = rowWidth;
32
- }
33
-
34
- return row;
35
- };
36
-
37
22
  const getContainerStyle = (extra?: any) => {
38
23
  let row = getStyle('container', {});
39
24
 
@@ -83,28 +68,6 @@ export default function UIList(props: ChildType) {
83
68
  return <>{empty}</>;
84
69
  };
85
70
 
86
- let RowItem = ({ item, index, children }) => {
87
- if (!original.click) {
88
- return (
89
- <View key={`k-${index}`} style={getRowStyle()}>
90
- {children}
91
- </View>
92
- );
93
- }
94
- return (
95
- <TouchableHighlight
96
- key={`k-${index}`}
97
- style={getRowStyle()}
98
- underlayColor={'transparent'}
99
- onPress={e => {
100
- e.stopPropagation();
101
- onClick(item);
102
- }}
103
- >
104
- {children}
105
- </TouchableHighlight>
106
- );
107
- };
108
71
  return (
109
72
  <>
110
73
  {original.search !== false && (
@@ -119,11 +82,9 @@ export default function UIList(props: ChildType) {
119
82
  <View style={getContainerStyle()}>
120
83
  <Empty />
121
84
  {items.map((item: any, i: number) => (
122
- <RowItem index={i} item={item}>
123
- <UIListRow scope={scope} item={item} index={i}>
124
- {props.children}
125
- </UIListRow>
126
- </RowItem>
85
+ <UIListRow scope={scope} item={item} index={i} styles={styles}>
86
+ {props.children}
87
+ </UIListRow>
127
88
  ))}
128
89
  {isShowAdd() && <>{add}</>}
129
90
  </View>
@@ -1,14 +1,17 @@
1
1
  import React, { useState } from 'react';
2
2
  import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
3
  import UIChildren from '../UIChildren';
4
+ import { TouchableHighlight, View } from 'react-native';
4
5
 
5
6
  interface UIListRowType extends ChildType {
6
7
  item: any;
7
8
  index: number;
9
+ styles: any;
8
10
  }
9
11
 
10
12
  export default function UIListRow(props: UIListRowType) {
11
13
  const parent = props.scope;
14
+ const original = parent.original;
12
15
  const item = props.item;
13
16
  const index = props.index;
14
17
  const name = `${parent.key('row', index)}`;
@@ -20,12 +23,56 @@ export default function UIListRow(props: UIListRowType) {
20
23
  type: 'row',
21
24
  data: item,
22
25
  };
23
- let [scope] = useState(ScopeUtils.create(row));
26
+ const styles = props.styles;
27
+ const cols = Utils.nvl(original.cols, 1);
28
+ const rowWidth = Math.floor(100 / cols) + '%';
29
+
30
+ const [scope] = useState(ScopeUtils.create(row));
31
+
32
+ const getStyle = (key: string, extra?: any) => {
33
+ return scope.getStyle(key, { ...extra, ...styles[key] });
34
+ };
35
+
36
+ const getRowStyle = (extra?: any) => {
37
+ let row = getStyle('row', {});
38
+
39
+ if (cols > 0) {
40
+ row.width = rowWidth;
41
+ }
42
+
43
+ return row;
44
+ };
45
+ let onClick = (item: any) => {
46
+ scope.call('click', { value: item, item, edit: true });
47
+ };
48
+
49
+ let RowItem = () => {
50
+ if (!original.click) {
51
+ return (
52
+ <View key={`k-${index}`} style={getRowStyle()}>
53
+ {props.children}
54
+ </View>
55
+ );
56
+ }
57
+ return (
58
+ <TouchableHighlight
59
+ key={`k-${index}`}
60
+ style={getRowStyle()}
61
+ underlayColor={'transparent'}
62
+ onPress={e => {
63
+ e.stopPropagation();
64
+ onClick(item);
65
+ }}
66
+ >
67
+ <>{props.children}</>
68
+ </TouchableHighlight>
69
+ );
70
+ };
24
71
 
25
72
  return (
26
73
  <>
27
74
  <UIChildren scope={scope} crud={scope.crud}>
28
- {props.children}
75
+ <RowItem />
29
76
  </UIChildren>
30
77
  </>
31
78
  );