Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: destructure props at top of render functions #3519

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
};

renderCheckbox() {
const {selectedIcon, label, testID, style, containerStyle, indeterminate, ...others} = this.props;
const {selectedIcon, label, testID, style, containerStyle, indeterminate, size = DEFAULT_SIZE, ...others} = this.props;
const verticalPadding = Math.max(0, (48 - size) / 2);
const horizontalPadding = verticalPadding;

return (
//@ts-ignore
<TouchableOpacity
Expand All @@ -263,6 +266,7 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
{...others}
style={[this.getBorderStyle(), style, !label && containerStyle]}
onPress={this.onPress}
hitSlop={{top: verticalPadding, bottom: verticalPadding, left: horizontalPadding, right: horizontalPadding}}
>
{
<Animated.View
Expand Down
14 changes: 11 additions & 3 deletions src/components/radioButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
}

render() {
const {onPress, onValueChange, containerStyle, contentOnLeft, ...others} = this.props;
const {onPress, onValueChange, containerStyle, contentOnLeft, size = DEFAULT_SIZE, iconOnRight, ...others} = this.props;
const Container = onPress || onValueChange ? TouchableOpacity : View;
const verticalPadding = Math.max(0, (48 - size) / 2);
const horizontalPadding = verticalPadding;

return (
// @ts-ignore
Expand All @@ -271,10 +273,16 @@ class RadioButton extends PureComponent<Props, RadioButtonState> {
style={containerStyle}
onPress={this.onPress}
{...this.getAccessibilityProps()}
hitSlop={Container === TouchableOpacity ? {
top: verticalPadding,
bottom: verticalPadding,
left: horizontalPadding,
right: horizontalPadding
} : undefined}
>
{!contentOnLeft && this.renderButton()}
{this.props.iconOnRight ? this.renderLabel() : this.renderIcon()}
{this.props.iconOnRight ? this.renderIcon() : this.renderLabel()}
{iconOnRight ? this.renderLabel() : this.renderIcon()}
{iconOnRight ? this.renderIcon() : this.renderLabel()}
{contentOnLeft && this.renderButton()}
</Container>
);
Expand Down
6 changes: 5 additions & 1 deletion src/components/switch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ class Switch extends Component<SwitchProps> {
}

render() {
const {...others} = this.props;
const {width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, ...others} = this.props;
const verticalPadding = Math.max(0, (48 - height) / 2);
const horizontalPadding = Math.max(0, (48 - width) / 2);

return (
// @ts-ignore
<TouchableOpacity
Expand All @@ -160,6 +163,7 @@ class Switch extends Component<SwitchProps> {
{...others}
style={this.getSwitchStyle()}
onPress={this.onPress}
hitSlop={{top: verticalPadding, bottom: verticalPadding, left: horizontalPadding, right: horizontalPadding}}
>
{this.renderThumb()}
</TouchableOpacity>
Expand Down