react-native-ui-lib 7.38.0 → 7.38.1-snapshot.6300
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/animatedImage/index.web.d.ts +10 -0
- package/src/components/animatedImage/index.web.js +52 -0
- package/src/components/button/ButtonConstants.d.ts +6 -0
- package/src/components/button/ButtonConstants.js +6 -0
- package/src/components/button/index.d.ts +18 -5
- package/src/components/button/index.js +16 -2
- package/src/components/checkbox/index.d.ts +1 -0
- package/src/components/checkbox/index.js +4 -1
- package/src/components/radioButton/index.js +8 -1
package/package.json
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @description: Image component that fades-in the image with animation once it's loaded
|
|
4
|
+
* @extends: Animated.Image
|
|
5
|
+
*/
|
|
6
|
+
declare const AnimatedImage: {
|
|
7
|
+
(props: any): React.JSX.Element;
|
|
8
|
+
displayName: string;
|
|
9
|
+
};
|
|
10
|
+
export default AnimatedImage;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { StyleSheet, Animated } from 'react-native';
|
|
3
|
+
import View from "../../components/view";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description: Image component that fades-in the image with animation once it's loaded
|
|
7
|
+
* @extends: Animated.Image
|
|
8
|
+
*/
|
|
9
|
+
const AnimatedImage = props => {
|
|
10
|
+
const {
|
|
11
|
+
containerStyle,
|
|
12
|
+
source,
|
|
13
|
+
loader,
|
|
14
|
+
style,
|
|
15
|
+
onLoad: propsOnLoad,
|
|
16
|
+
animationDuration = 300,
|
|
17
|
+
testID,
|
|
18
|
+
...others
|
|
19
|
+
} = props;
|
|
20
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
21
|
+
const opacity = new Animated.Value(0);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
// Fade in the image once it's loaded
|
|
24
|
+
if (!isLoading) {
|
|
25
|
+
Animated.timing(opacity, {
|
|
26
|
+
toValue: 1,
|
|
27
|
+
duration: animationDuration,
|
|
28
|
+
useNativeDriver: true // Note: native driver may not work for opacity on the web
|
|
29
|
+
}).start();
|
|
30
|
+
}
|
|
31
|
+
}, [isLoading, opacity, animationDuration]);
|
|
32
|
+
const onLoad = useCallback(event => {
|
|
33
|
+
setIsLoading(false);
|
|
34
|
+
propsOnLoad?.(event);
|
|
35
|
+
}, [propsOnLoad]);
|
|
36
|
+
return <View style={containerStyle}>
|
|
37
|
+
<Animated.Image {...others} source={source} style={[style, {
|
|
38
|
+
opacity
|
|
39
|
+
}]} // Apply the animated opacity
|
|
40
|
+
onLoad={onLoad} // Handle the onLoad event
|
|
41
|
+
testID={testID} />
|
|
42
|
+
{isLoading && loader && <View style={styles.loader}>{loader}</View>}
|
|
43
|
+
</View>;
|
|
44
|
+
};
|
|
45
|
+
AnimatedImage.displayName = 'AnimatedImage';
|
|
46
|
+
export default AnimatedImage;
|
|
47
|
+
const styles = StyleSheet.create({
|
|
48
|
+
loader: {
|
|
49
|
+
...StyleSheet.absoluteFillObject,
|
|
50
|
+
justifyContent: 'center'
|
|
51
|
+
}
|
|
52
|
+
});
|
|
@@ -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():
|
|
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:
|
|
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} hitSlop={this.getAccessibleHitSlop()} {...others} ref={forwardedRef}>
|
|
377
391
|
{this.props.children}
|
|
378
392
|
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
|
|
379
393
|
{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
|
}, {
|
|
@@ -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()}
|