react-native-ui-lib 7.38.0-snapshot.6240 → 7.38.0-snapshot.6267
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/package.json +1 -1
- package/src/components/hint/hooks/useHintLayout.js +2 -18
- package/src/components/picker/PickerItemsList.js +1 -3
- package/src/components/picker/helpers/usePickerSelection.d.ts +1 -2
- package/src/components/picker/helpers/usePickerSelection.js +4 -40
- package/src/components/picker/index.js +13 -22
- package/src/components/picker/types.d.ts +2 -18
- package/src/components/picker/helpers/usePickerDialogProps.d.ts +0 -17
- package/src/components/picker/helpers/usePickerDialogProps.js +0 -49
package/package.json
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
import _isEqual from "lodash/isEqual";
|
|
2
|
-
import { useState, useCallback, useRef
|
|
3
|
-
import { SafeAreaInsetsManager } from 'uilib-native';
|
|
4
|
-
import { Constants } from "../../../commons/new";
|
|
2
|
+
import { useState, useCallback, useRef } from 'react';
|
|
5
3
|
export default function useHintLayout({
|
|
6
4
|
onBackgroundPress,
|
|
7
5
|
targetFrame
|
|
8
6
|
}) {
|
|
9
7
|
const [targetLayoutState, setTargetLayout] = useState(targetFrame);
|
|
10
|
-
const [targetLayoutInWindowState, setTargetLayoutInWindow] = useState();
|
|
8
|
+
const [targetLayoutInWindowState, setTargetLayoutInWindow] = useState(targetFrame);
|
|
11
9
|
const [hintMessageWidth, setHintMessageWidth] = useState();
|
|
12
10
|
const targetRef = useRef(null);
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (targetFrame) {
|
|
15
|
-
if (!onBackgroundPress) {
|
|
16
|
-
setTargetLayoutInWindow(targetFrame);
|
|
17
|
-
} else {
|
|
18
|
-
SafeAreaInsetsManager.getSafeAreaInsets().then(insets => {
|
|
19
|
-
setTargetLayoutInWindow({
|
|
20
|
-
...targetFrame,
|
|
21
|
-
y: targetFrame.y + (insets?.top ?? 0) + Constants.getSafeAreaInsets().top
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}, []);
|
|
27
11
|
const onTargetLayout = useCallback(({
|
|
28
12
|
nativeEvent: {
|
|
29
13
|
layout
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _isUndefined from "lodash/isUndefined";
|
|
2
1
|
import _times from "lodash/times";
|
|
3
2
|
import _throttle from "lodash/throttle";
|
|
4
3
|
import _isFunction from "lodash/isFunction";
|
|
@@ -34,7 +33,6 @@ const PickerItemsList = props => {
|
|
|
34
33
|
useDialog,
|
|
35
34
|
mode,
|
|
36
35
|
testID,
|
|
37
|
-
selectionValidation,
|
|
38
36
|
showLoader,
|
|
39
37
|
customLoaderElement,
|
|
40
38
|
renderCustomTopElement
|
|
@@ -118,7 +116,7 @@ const PickerItemsList = props => {
|
|
|
118
116
|
{doneLabel ?? 'Select'}
|
|
119
117
|
</Text>
|
|
120
118
|
</View>;
|
|
121
|
-
} else if (
|
|
119
|
+
} else if (!useDialog || mode === PickerModes.MULTI) {
|
|
122
120
|
return <Modal.TopBar testID={`${props.testID}.topBar`} {...topBarProps} />;
|
|
123
121
|
}
|
|
124
122
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { PickerProps, PickerValue, PickerSingleValue, PickerMultiValue } from '../types';
|
|
3
|
-
interface UsePickerSelectionProps extends Pick<PickerProps, 'migrate' | 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode'
|
|
3
|
+
interface UsePickerSelectionProps extends Pick<PickerProps, 'migrate' | 'value' | 'onChange' | 'getItemValue' | 'topBarProps' | 'mode'> {
|
|
4
4
|
pickerExpandableRef: RefObject<any>;
|
|
5
5
|
setSearchValue: (searchValue: string) => void;
|
|
6
6
|
}
|
|
@@ -9,6 +9,5 @@ declare const usePickerSelection: (props: UsePickerSelectionProps) => {
|
|
|
9
9
|
onDoneSelecting: (item: PickerValue) => void;
|
|
10
10
|
toggleItemSelection: (item: PickerSingleValue) => void;
|
|
11
11
|
cancelSelect: () => void;
|
|
12
|
-
shouldDisableDoneButton: boolean | undefined;
|
|
13
12
|
};
|
|
14
13
|
export default usePickerSelection;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import _xor from "lodash/xor";
|
|
2
2
|
import _xorBy from "lodash/xorBy";
|
|
3
|
-
import _isFunction from "lodash/isFunction";
|
|
4
|
-
import _isUndefined from "lodash/isUndefined";
|
|
5
3
|
import { useCallback, useState, useEffect } from 'react';
|
|
6
4
|
import { PickerModes } from "../types";
|
|
7
5
|
const usePickerSelection = props => {
|
|
@@ -13,54 +11,22 @@ const usePickerSelection = props => {
|
|
|
13
11
|
pickerExpandableRef,
|
|
14
12
|
getItemValue,
|
|
15
13
|
setSearchValue,
|
|
16
|
-
mode
|
|
17
|
-
selectionValidation,
|
|
18
|
-
selectionOptions,
|
|
19
|
-
useDialog
|
|
14
|
+
mode
|
|
20
15
|
} = props;
|
|
21
|
-
const {
|
|
22
|
-
onValidationFailed,
|
|
23
|
-
validateOnStart,
|
|
24
|
-
onChangeValidity
|
|
25
|
-
} = selectionOptions || {};
|
|
26
16
|
const [multiDraftValue, setMultiDraftValue] = useState(value);
|
|
27
17
|
const [multiFinalValue, setMultiFinalValue] = useState(value);
|
|
28
|
-
const [isValid, setIsValid] = useState(undefined);
|
|
29
|
-
const _selectionValidation = item => {
|
|
30
|
-
if (useDialog) {
|
|
31
|
-
const isValid = selectionValidation?.(item);
|
|
32
|
-
if (!isValid) {
|
|
33
|
-
onValidationFailed?.(item);
|
|
34
|
-
}
|
|
35
|
-
setIsValid(isValid);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
18
|
useEffect(() => {
|
|
39
19
|
if (mode === PickerModes.MULTI && multiFinalValue !== value) {
|
|
40
20
|
setMultiDraftValue(value);
|
|
41
21
|
setMultiFinalValue(value);
|
|
42
22
|
}
|
|
43
23
|
}, [value]);
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
if (_isUndefined(selectionValidation)) {
|
|
46
|
-
setIsValid(true);
|
|
47
|
-
} else if (_isFunction(selectionValidation) && validateOnStart) {
|
|
48
|
-
_selectionValidation?.(value);
|
|
49
|
-
} else {
|
|
50
|
-
setIsValid(false);
|
|
51
|
-
}
|
|
52
|
-
}, []);
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (isValid !== undefined) {
|
|
55
|
-
onChangeValidity?.(isValid);
|
|
56
|
-
}
|
|
57
|
-
}, [isValid]);
|
|
58
24
|
const onDoneSelecting = useCallback(item => {
|
|
59
25
|
setSearchValue('');
|
|
60
26
|
setMultiFinalValue(item);
|
|
61
27
|
pickerExpandableRef.current?.closeExpandable?.();
|
|
62
28
|
onChange?.(item);
|
|
63
|
-
}, [onChange
|
|
29
|
+
}, [onChange]);
|
|
64
30
|
const toggleItemSelection = useCallback(item => {
|
|
65
31
|
let newValue;
|
|
66
32
|
const itemAsArray = [item];
|
|
@@ -69,9 +35,8 @@ const usePickerSelection = props => {
|
|
|
69
35
|
} else {
|
|
70
36
|
newValue = _xor(multiDraftValue, itemAsArray);
|
|
71
37
|
}
|
|
72
|
-
_selectionValidation(newValue);
|
|
73
38
|
setMultiDraftValue(newValue);
|
|
74
|
-
}, [multiDraftValue, getItemValue
|
|
39
|
+
}, [multiDraftValue, getItemValue]);
|
|
75
40
|
const cancelSelect = useCallback(() => {
|
|
76
41
|
setSearchValue('');
|
|
77
42
|
setMultiDraftValue(multiFinalValue);
|
|
@@ -82,8 +47,7 @@ const usePickerSelection = props => {
|
|
|
82
47
|
multiDraftValue,
|
|
83
48
|
onDoneSelecting,
|
|
84
49
|
toggleItemSelection,
|
|
85
|
-
cancelSelect
|
|
86
|
-
shouldDisableDoneButton: isValid
|
|
50
|
+
cancelSelect
|
|
87
51
|
};
|
|
88
52
|
};
|
|
89
53
|
export default usePickerSelection;
|
|
@@ -10,16 +10,19 @@ import TextField from "../textField";
|
|
|
10
10
|
import PickerItemsList from "./PickerItemsList";
|
|
11
11
|
import PickerItem from "./PickerItem";
|
|
12
12
|
import PickerContext from "./PickerContext";
|
|
13
|
-
|
|
14
|
-
import useFieldType from "./helpers/useFieldType";
|
|
15
|
-
import useImperativePickerHandle from "./helpers/useImperativePickerHandle";
|
|
16
|
-
import useNewPickerProps from "./helpers/useNewPickerProps";
|
|
17
|
-
import usePickerDialogProps from "./helpers/usePickerDialogProps";
|
|
13
|
+
import usePickerSelection from "./helpers/usePickerSelection";
|
|
18
14
|
import usePickerLabel from "./helpers/usePickerLabel";
|
|
19
15
|
import usePickerSearch from "./helpers/usePickerSearch";
|
|
20
|
-
import
|
|
16
|
+
import useImperativePickerHandle from "./helpers/useImperativePickerHandle";
|
|
17
|
+
import useFieldType from "./helpers/useFieldType";
|
|
18
|
+
import useNewPickerProps from "./helpers/useNewPickerProps";
|
|
19
|
+
// import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
|
|
21
20
|
import { extractPickerItems } from "./PickerPresenter";
|
|
22
21
|
import { PickerProps, PickerItemProps, PickerValue, PickerModes, PickerFieldTypes, PickerSearchStyle, RenderCustomModalProps, PickerItemsListProps, PickerMethods } from "./types";
|
|
22
|
+
const DEFAULT_DIALOG_PROPS = {
|
|
23
|
+
bottom: true,
|
|
24
|
+
width: '100%'
|
|
25
|
+
};
|
|
23
26
|
const Picker = React.forwardRef((props, ref) => {
|
|
24
27
|
const themeProps = useThemeProps(props, 'Picker');
|
|
25
28
|
const {
|
|
@@ -52,8 +55,6 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
52
55
|
accessibilityLabel,
|
|
53
56
|
accessibilityHint,
|
|
54
57
|
items: propItems,
|
|
55
|
-
selectionValidation,
|
|
56
|
-
selectionOptions,
|
|
57
58
|
showLoader,
|
|
58
59
|
customLoaderElement,
|
|
59
60
|
renderCustomTopElement,
|
|
@@ -100,8 +101,7 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
100
101
|
multiDraftValue,
|
|
101
102
|
onDoneSelecting,
|
|
102
103
|
toggleItemSelection,
|
|
103
|
-
cancelSelect
|
|
104
|
-
shouldDisableDoneButton
|
|
104
|
+
cancelSelect
|
|
105
105
|
} = usePickerSelection({
|
|
106
106
|
migrate,
|
|
107
107
|
value,
|
|
@@ -110,17 +110,8 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
110
110
|
getItemValue,
|
|
111
111
|
topBarProps,
|
|
112
112
|
setSearchValue,
|
|
113
|
-
mode
|
|
114
|
-
selectionValidation,
|
|
115
|
-
selectionOptions,
|
|
116
|
-
useDialog
|
|
113
|
+
mode
|
|
117
114
|
});
|
|
118
|
-
const {
|
|
119
|
-
dialogProps = {}
|
|
120
|
-
} = usePickerDialogProps({
|
|
121
|
-
...themeProps,
|
|
122
|
-
shouldDisableDoneButton
|
|
123
|
-
}, () => onDoneSelecting(multiDraftValue));
|
|
124
115
|
const {
|
|
125
116
|
label,
|
|
126
117
|
accessibilityInfo
|
|
@@ -210,12 +201,12 @@ const Picker = React.forwardRef((props, ref) => {
|
|
|
210
201
|
...topBarProps,
|
|
211
202
|
onCancel: cancelSelect,
|
|
212
203
|
onDone: mode === PickerModes.MULTI ? () => onDoneSelecting(multiDraftValue) : undefined
|
|
213
|
-
}} showSearch={showSearch} searchStyle={searchStyle} searchPlaceholder={searchPlaceholder} onSearchChange={_onSearchChange} renderCustomSearch={renderCustomSearch} renderHeader={renderHeader} listProps={listProps} useSafeArea={useSafeArea}
|
|
204
|
+
}} showSearch={showSearch} searchStyle={searchStyle} searchPlaceholder={searchPlaceholder} onSearchChange={_onSearchChange} renderCustomSearch={renderCustomSearch} renderHeader={renderHeader} listProps={listProps} useSafeArea={useSafeArea} showLoader={showLoader} customLoaderElement={customLoaderElement} renderCustomTopElement={renderCustomTopElement}>
|
|
214
205
|
{filteredItems}
|
|
215
206
|
</PickerItemsList>;
|
|
216
207
|
}, [testID, mode, useDialog, selectedItemPosition, topBarProps, cancelSelect, onDoneSelecting, multiDraftValue, showSearch, searchStyle, searchPlaceholder, _onSearchChange, renderCustomSearch, renderHeader, listProps, filteredItems, useSafeArea, useWheelPicker, items, showLoader]);
|
|
217
208
|
return <PickerContext.Provider value={contextValue}>
|
|
218
|
-
{<ExpandableOverlay ref={pickerExpandable} useDialog={useDialog || useWheelPicker} migrateDialog expandableContent={expandableModalContent} renderCustomOverlay={renderOverlay ? _renderOverlay : undefined} onPress={onPress} testID={testID} {...customPickerProps}
|
|
209
|
+
{<ExpandableOverlay ref={pickerExpandable} useDialog={useDialog || useWheelPicker} dialogProps={DEFAULT_DIALOG_PROPS} migrateDialog expandableContent={expandableModalContent} renderCustomOverlay={renderOverlay ? _renderOverlay : undefined} onPress={onPress} testID={testID} {...customPickerProps} disabled={themeProps.editable === false}>
|
|
219
210
|
{renderTextField()}
|
|
220
211
|
</ExpandableOverlay>}
|
|
221
212
|
</PickerContext.Provider>;
|
|
@@ -147,23 +147,7 @@ type PickerExpandableOverlayProps = {
|
|
|
147
147
|
*/
|
|
148
148
|
enableModalBlur?: boolean;
|
|
149
149
|
};
|
|
150
|
-
type
|
|
151
|
-
/**
|
|
152
|
-
* Callback for when field validated and failed
|
|
153
|
-
*/
|
|
154
|
-
onValidationFailed?: (value: PickerValue) => void;
|
|
155
|
-
};
|
|
156
|
-
type PickerSelectionValidation = {
|
|
157
|
-
/**
|
|
158
|
-
* Callback for when selection was made
|
|
159
|
-
*/
|
|
160
|
-
selectionValidation?: (value: PickerValue) => boolean;
|
|
161
|
-
/**
|
|
162
|
-
* Selection validation options
|
|
163
|
-
*/
|
|
164
|
-
selectionOptions?: PickerSelectionOptions;
|
|
165
|
-
};
|
|
166
|
-
export type PickerBaseProps = Omit<TextFieldProps, 'value' | 'onChange'> & PickerPropsDeprecation & PickerExpandableOverlayProps & PickerListProps & PickerSelectionValidation & {
|
|
150
|
+
export type PickerBaseProps = Omit<TextFieldProps, 'value' | 'onChange'> & PickerPropsDeprecation & PickerExpandableOverlayProps & PickerListProps & {
|
|
167
151
|
/**
|
|
168
152
|
* Use dialog instead of modal picker
|
|
169
153
|
*/
|
|
@@ -303,7 +287,7 @@ export interface PickerContextProps extends Pick<PickerProps, 'migrate' | 'value
|
|
|
303
287
|
onSelectedLayout: (event: any) => any;
|
|
304
288
|
selectionLimit: PickerProps['selectionLimit'];
|
|
305
289
|
}
|
|
306
|
-
export type PickerItemsListProps = Pick<PropsWithChildren<PickerProps>, 'topBarProps' | 'listProps' | 'renderHeader' | 'useSafeArea' | 'showLoader' | 'customLoaderElement' | 'renderCustomTopElement' | 'showSearch' | 'searchStyle' | 'searchPlaceholder' | 'onSearchChange' | 'renderCustomSearch' | 'children' | 'useWheelPicker' | '
|
|
290
|
+
export type PickerItemsListProps = Pick<PropsWithChildren<PickerProps>, 'topBarProps' | 'listProps' | 'renderHeader' | 'useSafeArea' | 'showLoader' | 'customLoaderElement' | 'renderCustomTopElement' | 'showSearch' | 'searchStyle' | 'searchPlaceholder' | 'onSearchChange' | 'renderCustomSearch' | 'children' | 'useWheelPicker' | 'useDialog' | 'mode' | 'testID'> & {
|
|
307
291
|
items?: {
|
|
308
292
|
value: any;
|
|
309
293
|
label: any;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { PickerProps } from '../types';
|
|
3
|
-
type HookProps = PickerProps & {
|
|
4
|
-
shouldDisableDoneButton?: boolean;
|
|
5
|
-
};
|
|
6
|
-
declare const usePickerDialogProps: (props: HookProps, onDone: any) => import("../../touchableOpacity").TouchableOpacityProps & import("../../../incubator/dialog/types")._DialogPropsOld & {
|
|
7
|
-
expandableContent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
8
|
-
useDialog?: boolean | undefined;
|
|
9
|
-
modalProps?: import("../../modal").ModalProps | undefined;
|
|
10
|
-
showTopBar?: boolean | undefined;
|
|
11
|
-
topBarProps?: import("../../modal").ModalTopBarProps | undefined;
|
|
12
|
-
renderCustomOverlay?: ((props: import("../../../incubator/expandableOverlay").RenderCustomOverlayProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null | undefined) | undefined;
|
|
13
|
-
disabled?: boolean | undefined;
|
|
14
|
-
} & {
|
|
15
|
-
children?: React.ReactNode;
|
|
16
|
-
};
|
|
17
|
-
export default usePickerDialogProps;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StyleSheet } from 'react-native';
|
|
3
|
-
import { PickerModes } from "../types";
|
|
4
|
-
import Button from "../../button";
|
|
5
|
-
import { Colors } from "../../../style";
|
|
6
|
-
const DIALOG_PROPS = {
|
|
7
|
-
bottom: true,
|
|
8
|
-
width: '100%',
|
|
9
|
-
useSafeArea: true
|
|
10
|
-
};
|
|
11
|
-
const usePickerDialogProps = (props, onDone) => {
|
|
12
|
-
const {
|
|
13
|
-
customPickerProps,
|
|
14
|
-
mode,
|
|
15
|
-
testID,
|
|
16
|
-
selectionOptions,
|
|
17
|
-
shouldDisableDoneButton
|
|
18
|
-
} = props;
|
|
19
|
-
const migrateDialog = customPickerProps?.migrateDialog;
|
|
20
|
-
const defaultProps = DIALOG_PROPS;
|
|
21
|
-
const {
|
|
22
|
-
validationMessage,
|
|
23
|
-
validationMessageStyle
|
|
24
|
-
} = selectionOptions || {};
|
|
25
|
-
const modifiedHeaderProps = migrateDialog && validationMessage && {
|
|
26
|
-
headerProps: {
|
|
27
|
-
trailingAccessory: validationMessage && <Button label="Save" link style={{
|
|
28
|
-
height: 30
|
|
29
|
-
}} onPress={mode === PickerModes.MULTI ? onDone : undefined} testID={`${testID}.dialog.header.save`} disabled={!shouldDisableDoneButton} />,
|
|
30
|
-
subtitle: !shouldDisableDoneButton && validationMessage,
|
|
31
|
-
subtitleStyle: [styles.validationMessage, validationMessageStyle],
|
|
32
|
-
...customPickerProps?.dialogProps?.headerProps
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const dialogProps = {
|
|
36
|
-
dialogProps: {
|
|
37
|
-
...defaultProps,
|
|
38
|
-
...customPickerProps?.dialogProps,
|
|
39
|
-
...modifiedHeaderProps
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return dialogProps;
|
|
43
|
-
};
|
|
44
|
-
export default usePickerDialogProps;
|
|
45
|
-
const styles = StyleSheet.create({
|
|
46
|
-
validationMessage: {
|
|
47
|
-
color: Colors.red30
|
|
48
|
-
}
|
|
49
|
-
});
|