@widergy/mobile-ui 0.35.2 → 0.35.3
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/CHANGELOG.md +8 -0
- package/lib/components/UTMenu/components/ListView/index.js +65 -0
- package/lib/components/UTMenu/components/ListView/proptypes.js +16 -0
- package/lib/components/UTMenu/components/MenuOption/index.js +7 -6
- package/lib/components/UTMenu/index.js +15 -35
- package/lib/components/UTSelect/componentes/MultipleItem/index.js +12 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [0.35.3](https://github.com/widergy/mobile-ui/compare/v0.35.2...v0.35.3) (2022-08-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* pr corrections ([b5a48ff](https://github.com/widergy/mobile-ui/commit/b5a48ff9748b20a6c1f4d50eb0be9a3bee5e4882))
|
|
7
|
+
* re-rendering of utmenu ([b0bd3eb](https://github.com/widergy/mobile-ui/commit/b0bd3eb868b8183a52cfd54186d6992c63966c4e))
|
|
8
|
+
|
|
1
9
|
## [0.35.2](https://github.com/widergy/mobile-ui/compare/v0.35.1...v0.35.2) (2022-08-12)
|
|
2
10
|
|
|
3
11
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import { FlatList } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import propTypes from './proptypes';
|
|
5
|
+
|
|
6
|
+
class ListView extends PureComponent {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.state = {
|
|
10
|
+
style: {
|
|
11
|
+
maxHeight: Math.min(props.maxHeight || props.windowHeight / 3, props.usableWindowHeight)
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
isSelected = item => {
|
|
17
|
+
const { filteredOptions, selectedOption, query, isMultiple } = this.props;
|
|
18
|
+
return isMultiple
|
|
19
|
+
? !!selectedOption?.find?.(elem => elem === item.value)
|
|
20
|
+
: !query
|
|
21
|
+
? item.id === selectedOption
|
|
22
|
+
: item.id === filteredOptions[0].id;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
handleOnPress = item => {
|
|
26
|
+
const { handleOptionPress, onPress } = this.props;
|
|
27
|
+
return handleOptionPress(item.action || (() => onPress(item)));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
renderItem = ({ item }) => {
|
|
31
|
+
const { MenuOptionComponent, propStyles } = this.props;
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<MenuOptionComponent
|
|
35
|
+
selected={this.isSelected(item)}
|
|
36
|
+
label={item.label}
|
|
37
|
+
onPress={this.handleOnPress}
|
|
38
|
+
styles={propStyles}
|
|
39
|
+
item={item}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
keyExtractor = (option, index) => option.id?.toString() || index.toString();
|
|
45
|
+
|
|
46
|
+
render() {
|
|
47
|
+
const { filteredOptions, ItemSeparatorComponent } = this.props;
|
|
48
|
+
const { style } = this.state;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<FlatList
|
|
52
|
+
style={style}
|
|
53
|
+
data={filteredOptions}
|
|
54
|
+
keyExtractor={this.keyExtractor}
|
|
55
|
+
keyboardShouldPersistTaps="always"
|
|
56
|
+
renderItem={this.renderItem}
|
|
57
|
+
ItemSeparatorComponent={ItemSeparatorComponent}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ListView.propTypes = propTypes;
|
|
64
|
+
|
|
65
|
+
export default ListView;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { bool, number, string, any, func } from 'prop-types';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
filteredOptions: any,
|
|
5
|
+
selectedOption: any,
|
|
6
|
+
query: string,
|
|
7
|
+
isMultiple: bool,
|
|
8
|
+
handleOptionPress: func,
|
|
9
|
+
onPress: func,
|
|
10
|
+
MenuOptionComponent: any,
|
|
11
|
+
propStyles: any,
|
|
12
|
+
maxHeight: number,
|
|
13
|
+
windowHeight: number,
|
|
14
|
+
usableWindowHeight: number,
|
|
15
|
+
ItemSeparatorComponent: any
|
|
16
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { bool, func, string } from 'prop-types';
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import { any, shape, bool, func, string } from 'prop-types';
|
|
2
|
+
import React, { memo } from 'react';
|
|
3
3
|
import { TouchableOpacity, Text, ViewPropTypes } from 'react-native';
|
|
4
4
|
|
|
5
5
|
import styles from './styles';
|
|
6
6
|
|
|
7
|
-
const MenuOption = ({ onPress, label, selected, styles: propStyles }) => (
|
|
7
|
+
const MenuOption = ({ onPress, label, selected, styles: propStyles, item }) => (
|
|
8
8
|
<TouchableOpacity
|
|
9
|
-
onPress={onPress}
|
|
9
|
+
onPress={() => onPress(item)}
|
|
10
10
|
style={[
|
|
11
11
|
styles.option,
|
|
12
12
|
propStyles?.menuOptionBase,
|
|
@@ -22,7 +22,8 @@ MenuOption.propTypes = {
|
|
|
22
22
|
onPress: func,
|
|
23
23
|
label: string,
|
|
24
24
|
selected: bool,
|
|
25
|
-
styles: ViewPropTypes.style
|
|
25
|
+
styles: ViewPropTypes.style,
|
|
26
|
+
item: shape(any)
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
export default MenuOption;
|
|
29
|
+
export default memo(MenuOption);
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import React, { Fragment, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Dimensions,
|
|
4
|
-
FlatList,
|
|
5
|
-
Keyboard,
|
|
6
|
-
KeyboardAvoidingView,
|
|
7
|
-
Modal,
|
|
8
|
-
TouchableOpacity,
|
|
9
|
-
View
|
|
10
|
-
} from 'react-native';
|
|
2
|
+
import { Dimensions, Keyboard, KeyboardAvoidingView, Modal, TouchableOpacity, View } from 'react-native';
|
|
11
3
|
|
|
12
4
|
import useKeyboardHeight from '../../hooks/useKeyboardHeight';
|
|
13
5
|
import UTTextInput from '../UTTextInput';
|
|
14
6
|
|
|
15
7
|
import MenuOption from './components/MenuOption';
|
|
8
|
+
import ListView from './components/ListView';
|
|
16
9
|
import MenuTypes from './proptypes';
|
|
17
10
|
import styles from './styles';
|
|
18
11
|
|
|
@@ -97,20 +90,11 @@ const UTMenu = ({
|
|
|
97
90
|
if (onClose) onClose();
|
|
98
91
|
};
|
|
99
92
|
|
|
100
|
-
const handleOptionPress = action =>
|
|
93
|
+
const handleOptionPress = action => {
|
|
101
94
|
action();
|
|
102
95
|
if (!isMultiple) closeMenu();
|
|
103
96
|
};
|
|
104
97
|
|
|
105
|
-
const defaultMaxHeight = windowHeight / 3;
|
|
106
|
-
|
|
107
|
-
const isSelected = item =>
|
|
108
|
-
isMultiple
|
|
109
|
-
? !!selectedOption?.find?.(elem => elem === item.value)
|
|
110
|
-
: !query
|
|
111
|
-
? item.id === selectedOption
|
|
112
|
-
: item.id === filteredOptions[0].id;
|
|
113
|
-
|
|
114
98
|
const focusSearchInput = () => withAutocomplete && searchTextInputRef.current?.focus();
|
|
115
99
|
|
|
116
100
|
return (
|
|
@@ -155,23 +139,19 @@ const UTMenu = ({
|
|
|
155
139
|
/>
|
|
156
140
|
</View>
|
|
157
141
|
)}
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
keyExtractor={(option, index) => option.id?.toString() || index.toString()}
|
|
164
|
-
keyboardShouldPersistTaps="always"
|
|
165
|
-
renderItem={({ item }) => (
|
|
166
|
-
<MenuOptionComponent
|
|
167
|
-
selected={isSelected(item)}
|
|
168
|
-
label={item.label}
|
|
169
|
-
onPress={handleOptionPress(item.action || (() => onPress(item)))}
|
|
170
|
-
styles={propStyles}
|
|
171
|
-
item={item}
|
|
172
|
-
/>
|
|
173
|
-
)}
|
|
142
|
+
<ListView
|
|
143
|
+
maxHeight={maxHeight}
|
|
144
|
+
windowHeight={windowHeight}
|
|
145
|
+
usableWindowHeight={usableWindowHeight}
|
|
146
|
+
filteredOptions={filteredOptions}
|
|
174
147
|
ItemSeparatorComponent={ItemSeparatorComponent}
|
|
148
|
+
MenuOptionComponent={MenuOptionComponent}
|
|
149
|
+
handleOptionPress={handleOptionPress}
|
|
150
|
+
onPress={onPress}
|
|
151
|
+
propStyles={propStyles}
|
|
152
|
+
selectedOption={selectedOption}
|
|
153
|
+
query={query}
|
|
154
|
+
isMultiple={isMultiple}
|
|
175
155
|
/>
|
|
176
156
|
</KeyboardAvoidingView>
|
|
177
157
|
</View>
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { any, bool, func, shape, string } from 'prop-types';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { memo } from 'react';
|
|
3
3
|
|
|
4
4
|
import Checkbox from '../../../Checkbox';
|
|
5
5
|
|
|
6
6
|
import styles from './styles';
|
|
7
7
|
|
|
8
|
-
const MultipleItem = ({ onPress, label, selected, checkboxProps }) => (
|
|
9
|
-
<Checkbox
|
|
8
|
+
const MultipleItem = ({ onPress, label, selected, checkboxProps, item }) => (
|
|
9
|
+
<Checkbox
|
|
10
|
+
label={label}
|
|
11
|
+
onPress={() => onPress(item)}
|
|
12
|
+
checked={selected}
|
|
13
|
+
style={styles.checkbox}
|
|
14
|
+
{...checkboxProps}
|
|
15
|
+
/>
|
|
10
16
|
);
|
|
11
17
|
|
|
12
18
|
MultipleItem.propTypes = {
|
|
13
19
|
onPress: func,
|
|
14
20
|
label: string,
|
|
15
21
|
selected: bool,
|
|
16
|
-
checkboxProps: shape(any)
|
|
22
|
+
checkboxProps: shape(any),
|
|
23
|
+
item: shape(any)
|
|
17
24
|
};
|
|
18
25
|
|
|
19
|
-
export default MultipleItem;
|
|
26
|
+
export default memo(MultipleItem);
|
package/package.json
CHANGED