react-native-ui-lib 7.38.0 → 7.38.1-snapshot.6294

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",
3
+ "version": "7.38.1-snapshot.6294",
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,
@@ -360,6 +374,7 @@ class Button extends PureComponent {
360
374
  animateLayout,
361
375
  modifiers,
362
376
  forwardedRef,
377
+ hitSlop: hitSlopProp,
363
378
  ...others
364
379
  } = this.props;
365
380
  const shadowStyle = this.getShadowStyle();
@@ -373,7 +388,7 @@ class Button extends PureComponent {
373
388
  const borderRadiusStyle = this.getBorderRadiusStyle();
374
389
  return <TouchableOpacity row centerV style={[this.styles.container, animateLayout && this.getAnimationDirectionStyle(), containerSizeStyle, this.isLink && this.styles.innerContainerLink, shadowStyle, margins, paddings, {
375
390
  backgroundColor
376
- }, borderRadiusStyle, outlineStyle, style]} activeOpacity={0.6} activeBackgroundColor={this.getActiveBackgroundColor()} onLayout={this.onLayout} onPress={onPress} disabled={disabled} testID={testID} {...others} ref={forwardedRef}>
391
+ }, borderRadiusStyle, outlineStyle, style]} activeOpacity={0.6} activeBackgroundColor={this.getActiveBackgroundColor()} onLayout={this.onLayout} onPress={onPress} disabled={disabled} testID={testID} hitSlop={hitSlopProp ?? this.getAccessibleHitSlop()} {...others} ref={forwardedRef}>
377
392
  {this.props.children}
378
393
  {this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
379
394
  {this.props.iconOnRight ? this.renderIcon() : this.renderLabel()}
@@ -117,6 +117,7 @@ declare class Checkbox extends Component<CheckboxProps, CheckboxState> {
117
117
  getLabelStyle: () => {
118
118
  color: string;
119
119
  };
120
+ getAccessibleHitSlop(size: number): number;
120
121
  renderCheckbox(): React.JSX.Element;
121
122
  render(): React.JSX.Element;
122
123
  validate: () => void;
@@ -144,6 +144,9 @@ class Checkbox extends Component {
144
144
  color: this.props.disabled ? Colors.$textDisabled : this.state.showError ? Colors.$textDangerLight : Colors.$textDefault
145
145
  };
146
146
  };
147
+ getAccessibleHitSlop(size) {
148
+ return Math.max(0, (48 - size) / 2);
149
+ }
147
150
  renderCheckbox() {
148
151
  const {
149
152
  selectedIcon,
@@ -156,7 +159,7 @@ class Checkbox extends Component {
156
159
  } = this.props;
157
160
  return (
158
161
  //@ts-ignore
159
- <TouchableOpacity {...this.getAccessibilityProps()} activeOpacity={1} testID={testID} {...others} style={[this.getBorderStyle(), style, !label && containerStyle]} onPress={this.onPress}>
162
+ <TouchableOpacity {...this.getAccessibilityProps()} activeOpacity={1} testID={testID} {...others} style={[this.getBorderStyle(), style, !label && containerStyle]} onPress={this.onPress} hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}>
160
163
  {<Animated.View style={[this.styles.container, {
161
164
  opacity: this.animationStyle.opacity
162
165
  }, {
@@ -1,29 +1,13 @@
1
1
  import _isEqual from "lodash/isEqual";
2
- import { useState, useCallback, useRef, useEffect } from 'react';
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
@@ -179,6 +179,13 @@ class RadioButton extends PureComponent {
179
179
  }]} />
180
180
  </View>;
181
181
  }
182
+ getAccessibleHitSlop(size) {
183
+ const verticalPadding = Math.max(0, (48 - size) / 2);
184
+ return {
185
+ top: verticalPadding,
186
+ bottom: verticalPadding
187
+ };
188
+ }
182
189
  render() {
183
190
  const {
184
191
  onPress,
@@ -190,7 +197,7 @@ class RadioButton extends PureComponent {
190
197
  const Container = onPress || onValueChange ? TouchableOpacity : View;
191
198
  return (
192
199
  // @ts-ignore
193
- <Container row centerV activeOpacity={1} {...others} style={containerStyle} onPress={this.onPress} {...this.getAccessibilityProps()}>
200
+ <Container row centerV activeOpacity={1} {...others} style={containerStyle} onPress={this.onPress} {...this.getAccessibilityProps()} hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}>
194
201
  {!contentOnLeft && this.renderButton()}
195
202
  {this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
196
203
  {this.props.iconOnRight ? this.renderIcon() : this.renderLabel()}