-
-
Notifications
You must be signed in to change notification settings - Fork 982
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
Split layout props in GenericTouchable instead of using containerStyle #1617
base: main
Are you sure you want to change the base?
Conversation
5af0d1f
to
b19d66c
Compare
@@ -274,11 +272,10 @@ export default class GenericTouchable extends Component< | |||
shouldActivateOnStart={this.props.shouldActivateOnStart} | |||
disallowInterruption={this.props.disallowInterruption} | |||
testID={this.props.testID} | |||
{...coreProps} |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@yfunk I was also doing something like this in my Touchable component. I've taken the code and revised it to make sure all styles are included. Let me know what you think about this approach. Will see if I can add an example too to test complex layout cases. |
The reason for I solve this by removing the
Then we can remove the View and therefore have the same behavior as in RN. If you want I can create a PR with this so you can have a look, I think it's better to skip the wdyt? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janicduplessis Sorry for my late answer on this. I left a few comments, but overall the approach looks good to me 👍
@@ -0,0 +1,61 @@ | |||
import { FlexStyle, StyleProp, StyleSheet } from 'react-native'; | |||
|
|||
const OUTER_PROPS: { [key in keyof FlexStyle]?: true } = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if these are really all the style props that need to be applied to the outer view or if there are more (e.g. backfaceVisibility
, elevation
, transform
and all of ShadowStyleIOS
).
It would probably be best to add complex layout examples to test this, as you mentioned.
@@ -261,10 +259,11 @@ export default class GenericTouchable extends Component< | |||
onLayout: this.props.onLayout, | |||
hitSlop: this.props.hitSlop, | |||
}; | |||
const { outer, inner } = splitStyleProp(this.props.style); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style
prop will be split on every render (and also causes bridge traffic since the object changes). Not sure if this has any noticeable performance implications but that's something to keep in mind since some screens may contain a lot of touchables.
* </View> | ||
* ); | ||
*/ | ||
export default function splitStyleProp<T extends FlexStyle>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be splitStyleProp<T extends ViewStyle>
for better clarity.
This was also the original approach of this PR, but unfortunately the extra |
@janicduplessis, what's the state on this? |
I ended up hitting some edge cases where splitting props broke certain layouts, I don't remember exactly what, but will have to have another look to see if I can figure out something. |
Description
Touchable components do not layout as expected since they are wrapped in an extra view. To workaround this they have an extra
containerStyle
prop, but this is confusing and different from the ones inreact-native
.This removes the
containerStyle
props and instead split the style prop passed between styles that should apply to the inner and outer view. This makes it seemlessly behave as if it was a single view.Test plan
Using something like:
Before:
After: