react-native-ui-lib 7.38.0-snapshot.6240 → 7.38.0-snapshot.6268

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ui-lib",
3
- "version": "7.38.0-snapshot.6240",
3
+ "version": "7.38.0-snapshot.6268",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "author": "Ethan Sharabi <ethan.shar@gmail.com>",
@@ -17,4 +17,10 @@ export declare const MIN_WIDTH: {
17
17
  MEDIUM: number;
18
18
  LARGE: number;
19
19
  };
20
+ export declare const SIZE_TO_VERTICAL_HITSLOP: {
21
+ readonly xSmall: 30;
22
+ readonly small: 25;
23
+ readonly medium: 20;
24
+ readonly large: 15;
25
+ };
20
26
  export declare const DEFAULT_SIZE = ButtonSize.large;
@@ -17,4 +17,10 @@ export const MIN_WIDTH = {
17
17
  MEDIUM: 77,
18
18
  LARGE: 90
19
19
  };
20
+ export const SIZE_TO_VERTICAL_HITSLOP = {
21
+ [ButtonSize.xSmall]: 30,
22
+ [ButtonSize.small]: 25,
23
+ [ButtonSize.medium]: 20,
24
+ [ButtonSize.large]: 15
25
+ };
20
26
  export const DEFAULT_SIZE = ButtonSize.large;
@@ -11,9 +11,7 @@ declare class Button extends PureComponent<Props, ButtonState> {
11
11
  static sizes: typeof ButtonSize;
12
12
  static animationDirection: typeof ButtonAnimationDirection;
13
13
  constructor(props: Props);
14
- state: {
15
- size: undefined;
16
- };
14
+ state: Record<'size', undefined | number>;
17
15
  styles: {
18
16
  container: {
19
17
  backgroundColor: string;
@@ -370,7 +368,14 @@ declare class Button extends PureComponent<Props, ButtonState> {
370
368
  getLabelColor(): string | undefined;
371
369
  getIconColor(): string | undefined;
372
370
  getLabelSizeStyle(): TextStyle | undefined;
373
- getContainerSizeStyle(): any;
371
+ getContainerSizeStyle(): Partial<{
372
+ height: number;
373
+ width: number;
374
+ padding: number;
375
+ paddingVertical: number;
376
+ paddingHorizontal: number;
377
+ minWidth: number;
378
+ }>;
374
379
  getOutlineStyle(): {
375
380
  borderWidth: number;
376
381
  borderColor: string;
@@ -391,10 +396,18 @@ declare class Button extends PureComponent<Props, ButtonState> {
391
396
  })[] | undefined;
392
397
  getIconStyle(): [ImageStyle, StyleProp<ImageStyle>];
393
398
  getAnimationDirectionStyle(): {
394
- alignSelf: string;
399
+ readonly alignSelf: "flex-start";
400
+ } | {
401
+ readonly alignSelf: "flex-end";
395
402
  } | undefined;
396
403
  renderIcon(): React.JSX.Element | null;
397
404
  renderLabel(): React.JSX.Element | null;
405
+ getAccessibleHitSlop(): {
406
+ top: number;
407
+ bottom: number;
408
+ left: number;
409
+ right: number;
410
+ };
398
411
  render(): React.JSX.Element;
399
412
  }
400
413
  export { Button };
@@ -7,7 +7,7 @@ import TouchableOpacity from "../touchableOpacity";
7
7
  import Text from "../text";
8
8
  import Icon from "../icon";
9
9
  import { ButtonSize, ButtonAnimationDirection, ButtonProps, DEFAULT_PROPS } from "./types";
10
- import { PADDINGS, HORIZONTAL_PADDINGS, MIN_WIDTH, DEFAULT_SIZE } from "./ButtonConstants";
10
+ import { PADDINGS, HORIZONTAL_PADDINGS, MIN_WIDTH, DEFAULT_SIZE, SIZE_TO_VERTICAL_HITSLOP } from "./ButtonConstants";
11
11
  export { ButtonSize, ButtonAnimationDirection, ButtonProps };
12
12
  class Button extends PureComponent {
13
13
  static displayName = 'Button';
@@ -351,6 +351,20 @@ class Button extends PureComponent {
351
351
  }
352
352
  return null;
353
353
  }
354
+ getAccessibleHitSlop() {
355
+ const containerStyle = this.getContainerSizeStyle();
356
+ const isWidthSet = containerStyle.width !== undefined || containerStyle.minWidth !== undefined;
357
+ const width = containerStyle.width || containerStyle.minWidth || 0;
358
+ const widthWithPadding = width + (containerStyle.paddingHorizontal || containerStyle.padding || 0) * 2;
359
+ const horizontalHitslop = isWidthSet ? Math.max(0, (48 - widthWithPadding) / 2) : 10;
360
+ const verticalHitslop = (containerStyle.height ? Math.max(0, 48 - containerStyle.height) : SIZE_TO_VERTICAL_HITSLOP[this.props.size || DEFAULT_SIZE]) / 2;
361
+ return {
362
+ top: verticalHitslop,
363
+ bottom: verticalHitslop,
364
+ left: horizontalHitslop,
365
+ right: horizontalHitslop
366
+ };
367
+ }
354
368
  render() {
355
369
  const {
356
370
  onPress,
@@ -373,7 +387,7 @@ class Button extends PureComponent {
373
387
  const borderRadiusStyle = this.getBorderRadiusStyle();
374
388
  return <TouchableOpacity row centerV style={[this.styles.container, animateLayout && this.getAnimationDirectionStyle(), containerSizeStyle, this.isLink && this.styles.innerContainerLink, shadowStyle, margins, paddings, {
375
389
  backgroundColor
376
- }, borderRadiusStyle, outlineStyle, style]} activeOpacity={0.6} activeBackgroundColor={this.getActiveBackgroundColor()} onLayout={this.onLayout} onPress={onPress} disabled={disabled} testID={testID} {...others} ref={forwardedRef}>
390
+ }, borderRadiusStyle, outlineStyle, style]} activeOpacity={0.6} activeBackgroundColor={this.getActiveBackgroundColor()} onLayout={this.onLayout} onPress={onPress} disabled={disabled} testID={testID} {...others} ref={forwardedRef} hitSlop={this.getAccessibleHitSlop()}>
377
391
  {this.props.children}
378
392
  {this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
379
393
  {this.props.iconOnRight ? this.renderIcon() : this.renderLabel()}
@@ -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 (_isUndefined(selectionValidation) && (!useDialog || mode === PickerModes.MULTI)) {
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' | 'selectionValidation' | 'selectionOptions' | 'useDialog'> {
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, useDialog, selectionValidation]);
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, useDialog, _selectionValidation]);
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
- // import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
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 usePickerSelection from "./helpers/usePickerSelection";
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} selectionValidation={selectionValidation} showLoader={showLoader} customLoaderElement={customLoaderElement} renderCustomTopElement={renderCustomTopElement}>
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} dialogProps={dialogProps} disabled={themeProps.editable === false}>
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 PickerSelectionOptions = Pick<TextFieldProps, 'validateOnStart' | 'onChangeValidity' | 'validationMessage' | 'validationMessageStyle'> & {
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' | 'selectionValidation' | 'useDialog' | 'mode' | 'testID'> & {
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
- });