Skip to content

Commit 5aa435d

Browse files
authored
Merge branch 'master' into master
2 parents a6b49cf + 2bd0d9a commit 5aa435d

File tree

8 files changed

+55
-47
lines changed

8 files changed

+55
-47
lines changed

demo/src/screens/__tests__/__snapshots__/TextFieldScreen.spec.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,10 +3899,10 @@ exports[`TextField Screen renders screen 1`] = `
38993899
focusable={true}
39003900
hitSlop={
39013901
{
3902-
"bottom": 7.5,
3903-
"left": 10,
3904-
"right": 10,
3905-
"top": 7.5,
3902+
"bottom": 20,
3903+
"left": 20,
3904+
"right": 20,
3905+
"top": 20,
39063906
}
39073907
}
39083908
onClick={[Function]}

demo/src/screens/componentScreens/CheckboxScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class CheckboxScreen extends Component {
8989
disabled
9090
value={this.state.value5}
9191
onValueChange={value5 => this.setState({value5})}
92-
style={{marginRight: 10}}
92+
style={{marginRight: 20}}
9393
/>
9494
<Checkbox
9595
disabled

demo/src/screens/componentScreens/HintsScreen.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {Alert, ViewStyle} from 'react-native';
4-
import {Colors, View, Text, Hint, Button, Assets, Incubator} from 'react-native-ui-lib';
4+
import {Colors, View, Text, Hint, Button, Assets, Incubator, Constants} from 'react-native-ui-lib';
55
import {renderMultipleSegmentOptions, renderBooleanOption} from '../ExampleScreenPresenter';
66

77
const settingsIcon = require('../../assets/icons/settings.png');
88
const reactions = ['❤️', '😮', '😔', '😂', '😡'];
99

1010
type HintScreenProps = {};
1111

12+
const SHORT_MESSAGE = 'Add other cool and useful stuff.';
13+
const DEFAULT_MESSAGE = 'Add other cool and useful stuff through adding apps to your visitors to enjoy.';
14+
const TARGET_FRAMES_MESSAGE = 'Press Back button to go to previous screen';
15+
1216
export default class HintsScreen extends Component<HintScreenProps> {
1317
state = {
1418
showHint: true,
@@ -135,10 +139,14 @@ export default class HintsScreen extends Component<HintScreenProps> {
135139
showReactionStrip,
136140
enableShadow
137141
} = this.state;
138-
const targetFrame = {x: 140, y: 100, width: 10, height: 10};
139-
const message = useShortMessage
140-
? 'Add other cool and useful stuff.'
141-
: 'Add other cool and useful stuff through adding apps to your visitors to enjoy.';
142+
const targetFrame = {
143+
x: 20,
144+
y: Constants.getSafeAreaInsets().top + Constants.statusBarHeight,
145+
width: 1,
146+
height: 1
147+
};
148+
149+
const message = useTargetFrame ? TARGET_FRAMES_MESSAGE : useShortMessage ? SHORT_MESSAGE : DEFAULT_MESSAGE;
142150
const color = !showCustomContent && showReactionStrip ? {color: Colors.$backgroundDefault} : undefined;
143151

144152
const hintKey = `${useSideTip}-${targetPosition}-${useShortMessage}-${showIcon}-${useTargetFrame}-${showCustomContent}-${showReactionStrip}`;
@@ -170,14 +178,14 @@ export default class HintsScreen extends Component<HintScreenProps> {
170178
icon={showIcon ? settingsIcon : undefined}
171179
// iconStyle={{tintColor: 'red'}}
172180
// offset={35}
173-
position={showBottomHint ? Hint.positions.BOTTOM : Hint.positions.TOP}
174-
useSideTip={useSideTip}
181+
position={showBottomHint || useTargetFrame ? Hint.positions.BOTTOM : Hint.positions.TOP}
182+
useSideTip={useSideTip || useTargetFrame}
175183
key={hintKey}
176184
onPress={this.onHintPressed}
177185
targetFrame={useTargetFrame ? targetFrame : undefined}
178186
// borderRadius={BorderRadiuses.br40}
179187
// edgeMargins={30}
180-
onBackgroundPress={useBackdrop && !useTargetFrame ? this.toggleHint : undefined}
188+
onBackgroundPress={useBackdrop || useTargetFrame ? this.toggleHint : undefined}
181189
backdropColor={Colors.rgba(Colors.$backgroundInverted, 0.3)}
182190
customContent={
183191
showCustomContent
@@ -207,17 +215,6 @@ export default class HintsScreen extends Component<HintScreenProps> {
207215

208216
{useTargetFrame && (
209217
<>
210-
<View
211-
bg-red50
212-
style={{
213-
position: 'absolute',
214-
top: targetFrame.y,
215-
left: targetFrame.x,
216-
width: targetFrame.width,
217-
height: targetFrame.height
218-
}}
219-
/>
220-
221218
<View absL absB margin-page>
222219
<Button label="Show Hint" onPress={this.toggleHint}/>
223220
</View>

demo/src/screens/componentScreens/RadioButtonScreen.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default class RadioButtonScreen extends Component {
6969
Radio Buttons
7070
</Text>
7171

72-
<RadioGroup initialValue={this.state.color || null} onValueChange={value => this.setState({color: value})}>
72+
<RadioGroup gap-s4 initialValue={this.state.color || null} onValueChange={value => this.setState({color: value})}>
7373
<Text marginB-20 text60 $textDefault>
7474
Select a color{'\n'}
7575
(enum with default value)
@@ -82,6 +82,7 @@ export default class RadioButtonScreen extends Component {
8282
</RadioGroup>
8383

8484
<RadioGroup
85+
gap-s4
8586
marginT-30
8687
initialValue={this.state.textSide}
8788
onValueChange={value => this.setState({textSide: value})}
@@ -96,7 +97,7 @@ export default class RadioButtonScreen extends Component {
9697
<Text marginT-10>You chose: {this.state.textSide}</Text>
9798
</RadioGroup>
9899

99-
<RadioGroup marginT-30 initialValue={this.state.value} onValueChange={value => this.setState({value})}>
100+
<RadioGroup gap-s4 marginT-30 initialValue={this.state.value} onValueChange={value => this.setState({value})}>
100101
<Text marginB-20 text60 $textDefault>
101102
Yes or No?
102103
</Text>
@@ -112,6 +113,7 @@ export default class RadioButtonScreen extends Component {
112113
</Text>
113114
<View row centerV marginB-10>
114115
<RadioButton
116+
gap-s4
115117
selected={this.state.individualValue2}
116118
onPress={() => this.setState({individualValue2: !this.state.individualValue2})}
117119
label="Individual Radio Button (with style)"

src/components/button/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,17 @@ class Button extends PureComponent<Props, ButtonState> {
368368
}
369369

370370
render() {
371-
const {onPress, disabled, style, testID, animateLayout, modifiers, forwardedRef, ...others} = this.props;
371+
const {
372+
onPress,
373+
disabled,
374+
style,
375+
testID,
376+
animateLayout,
377+
modifiers,
378+
forwardedRef,
379+
hitSlop: hitSlopProp,
380+
...others
381+
} = this.props;
372382
const shadowStyle = this.getShadowStyle();
373383
const {margins, paddings} = modifiers;
374384
const backgroundColor = this.getBackgroundColor();
@@ -399,9 +409,9 @@ class Button extends PureComponent<Props, ButtonState> {
399409
onPress={onPress}
400410
disabled={disabled}
401411
testID={testID}
412+
hitSlop={hitSlopProp ?? this.getAccessibleHitSlop()}
402413
{...others}
403414
ref={forwardedRef}
404-
hitSlop={this.getAccessibleHitSlop()}
405415
>
406416
{this.props.children}
407417
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}

src/components/checkbox/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,13 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
252252
};
253253
};
254254

255+
getAccessibleHitSlop(size: number) {
256+
return Math.max(0, (48 - size) / 2);
257+
}
258+
255259
renderCheckbox() {
256260
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props;
261+
257262
return (
258263
//@ts-ignore
259264
<TouchableOpacity
@@ -263,6 +268,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
263268
{...others}
264269
style={[this.getBorderStyle(), style, !label && containerStyle]}
265270
onPress={this.onPress}
271+
hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}
266272
>
267273
{
268274
<Animated.View

src/components/hint/hooks/useHintLayout.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
import {type ElementRef, useState, useCallback, useRef, useEffect} from 'react';
1+
import {type ElementRef, useState, useCallback, useRef} from 'react';
22
import type {LayoutChangeEvent, LayoutRectangle, View as RNView} from 'react-native';
33
import _ from 'lodash';
4-
import {SafeAreaInsetsManager} from 'uilib-native';
54
import {HintProps} from '../types';
6-
import {Constants} from '../../../commons/new';
75

86
type UseHintLayoutProps = Pick<HintProps, 'onBackgroundPress' | 'targetFrame'>;
97

108
export default function useHintLayout({onBackgroundPress, targetFrame}: UseHintLayoutProps) {
119
const [targetLayoutState, setTargetLayout] = useState<LayoutRectangle | undefined>(targetFrame);
12-
const [targetLayoutInWindowState, setTargetLayoutInWindow] = useState<LayoutRectangle | undefined>();
10+
const [targetLayoutInWindowState, setTargetLayoutInWindow] = useState<LayoutRectangle | undefined>(targetFrame);
1311
const [hintMessageWidth, setHintMessageWidth] = useState<number | undefined>();
1412
const targetRef = useRef<ElementRef<typeof RNView> | null>(null);
1513

16-
useEffect(() => {
17-
if (targetFrame) {
18-
if (!onBackgroundPress) {
19-
setTargetLayoutInWindow(targetFrame);
20-
} else {
21-
SafeAreaInsetsManager.getSafeAreaInsets().then(insets => {
22-
setTargetLayoutInWindow({
23-
...targetFrame,
24-
y: targetFrame.y + (insets?.top ?? 0) + Constants.getSafeAreaInsets().top
25-
});
26-
});
27-
}
28-
}
29-
}, []);
30-
3114
const onTargetLayout = useCallback(({nativeEvent: {layout}}: LayoutChangeEvent) => {
3215
if (!_.isEqual(targetLayoutState, layout)) {
3316
setTargetLayout(layout);

src/components/radioButton/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
257257
);
258258
}
259259

260+
getAccessibleHitSlop(size: number) {
261+
const verticalPadding = Math.max(0, (48 - size) / 2);
262+
263+
return {
264+
top: verticalPadding,
265+
bottom: verticalPadding
266+
};
267+
}
268+
260269
render() {
261270
const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props;
262271
const Container = onPress || onValueChange ? TouchableOpacity : View;
@@ -271,6 +280,7 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
271280
style={containerStyle}
272281
onPress={this.onPress}
273282
{...this.getAccessibilityProps()}
283+
hitSlop={this.getAccessibleHitSlop(this.props.size || DEFAULT_SIZE)}
274284
>
275285
{!contentOnLeft && this.renderButton()}
276286
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}

0 commit comments

Comments
 (0)