Skip to content

Split layout props in GenericTouchable instead of using containerStyle #1617

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
17 changes: 7 additions & 10 deletions src/components/touchables/GenericTouchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Component } from 'react';
import {
Animated,
Platform,
StyleProp,
ViewStyle,
TouchableWithoutFeedbackProps,
} from 'react-native';

Expand All @@ -18,6 +16,8 @@ import {
import { NativeViewGestureHandlerPayload } from '../../handlers/NativeViewGestureHandler';
import { TouchableNativeFeedbackExtraProps } from './TouchableNativeFeedback.android';

const AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);

/**
* Each touchable is a states' machine which preforms transitions.
* On very beginning (and on the very end or recognition) touchable is
Expand Down Expand Up @@ -46,8 +46,6 @@ export interface GenericTouchableProps extends TouchableWithoutFeedbackProps {
nativeID?: string;
shouldActivateOnStart?: boolean;
disallowInterruption?: boolean;

containerStyle?: StyleProp<ViewStyle>;
}

interface InternalProps {
Expand Down Expand Up @@ -263,8 +261,8 @@ export default class GenericTouchable extends Component<
};

return (
<BaseButton
style={this.props.containerStyle}
<AnimatedBaseButton
style={this.props.style}
onHandlerStateChange={
// TODO: not sure if it can be undefined instead of null
this.props.disabled ? undefined : this.onHandlerStateChange
Expand All @@ -274,11 +272,10 @@ export default class GenericTouchable extends Component<
shouldActivateOnStart={this.props.shouldActivateOnStart}
disallowInterruption={this.props.disallowInterruption}
testID={this.props.testID}
{...coreProps}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does AnimatedBaseButton actually support all the accessibility props from coreProps? As far as I know this is the reason for using nested Views inside *Button components (docs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea looks like you’re right, I think it would be possible to keep the extra view, but split the style between the 2 views to make sure it lays out as expected if it was only a single view.

For example the flex style needs to be on the outer view while flexDirection should be on the inner one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about doing the same thing when making my own touchable component, but turns out View has quite a few style props so I didn't bother in the end (here's the list).

This would definitely be a nice feature though if you can find a neat way to split the styles.

{...this.props.extraButtonProps}>
<Animated.View {...coreProps} style={this.props.style}>
{this.props.children}
</Animated.View>
</BaseButton>
{this.props.children}
</AnimatedBaseButton>
);
}
}