-
-
Notifications
You must be signed in to change notification settings - Fork 1k
display: contents based button styling
#3634
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
base: next
Are you sure you want to change the base?
Conversation
c5661d1 to
fbf37bb
Compare
612fb8e to
773da37
Compare
773da37 to
d735767
Compare
...act/renderer/components/rngesturehandler_codegen/RNGestureHandlerButtonWrapperShadowNode.cpp
Outdated
Show resolved
Hide resolved
...react/renderer/components/rngesturehandler_codegen/RNGestureHandlerButtonWrapperShadowNode.h
Outdated
Show resolved
Hide resolved
| // TODO: figure out how to do it correctly | ||
| } else if (child is ViewGroup && child.isNotEmpty()) { | ||
| val grandChild = child.getChildAt(0) | ||
| if (grandChild is RNGestureHandlerButtonViewManager.ButtonViewGroup) { | ||
| grandChild.id | ||
| } else { | ||
| child.id | ||
| } |
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.
Okay, for now I don't have better way of doing this. This one seems ok though.
What I'd change is to extract this into helper (like isGestureHandlerButton or something along this).
If you prefer not to do this, I'd combine it into one condition to avoid nesting, i.e.
else if (child is ViewGroup && child.isNotEmpty() && child.getChildAt(0) is RNGestureHandlerButtonViewManager.ButtonViewGroup) {
child.getChildAt(0).id
} else {
child.id
}(but as I think about it now, it still doesn't look great)
| view = componentView.contentView; | ||
| } else if (componentView.subviews.count > 0) { | ||
| view = componentView.subviews[0]; | ||
| if ([view isKindOfClass:[RCTViewComponentView class]]) { |
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.
Similar, to android, probably we could somehow try to extract this button specific logic. Also, wouldn't it be possible to check directly for RNGestureHandlerButtonComponentView? Or is there a specific reason why you don't want to do this?
if ([view isKindOfClass:[RNGestureHandlerButtonComponentView class]]) {
RNGestureHandlerButtonComponentView *componentView = (RNGestureHandlerButtonComponentView *)view;
if (componentView.contentView != nil) {
view = componentView.contentView;
}
}
Description
Changes the button implementation of the native
GestureHandlerButtoncomponent, not to re-export the button component. Instead, it provides a "sandwich" implementation based ondisplay: contents.The issues we had with the styling of the buttons in the past stemmed from it extending
ViewGroupinstead ofReactViewGroup. This cannot be changed due to the difference in handling ofonTouchEvent. We experimented with wrapping the button with aViewin the past, but properly handling layout turned out to be quite a challenge. Hopefully, with the addition ofdisplay: contents, this will be easier now.This PR changes the structure of the button to be:
RNGestureHandlerButtonWrapperNativeComponentViewButtonComponentThe styles passed from the user are split into two categories:
Those affecting the layout need to be set on the button itself, while visual changes need to be set on the View wrapping it. Exceptions are:
zIndex,transform, andtransformOrigin, which need to be on the View.zIndexbecause the View is being rendered in the hierarchy at the level the button would be expected, and transforms to properly calculate touch coordinate transforms.Why not just
ButtonComponent?We need a
Viewcomponent as its parent to handle all styles that React Native supports properly.Why not just
ButtonComponentwrapped withView?In order for the view to always match the layout of the button, we need to set it at the shadow node level. Shadow nodes only have references to their children, not their parents. To have access to the layout of the button and the ability to copy it to the view wrapping it, there needs to be one more node as the parent of that subtree. That node is responsible for making sure that the size and positioning of the View match the Button.
The native components for the wrapper serve no purpose, since it's being rendered with
display: contents, but RN doesn't know that - there needs to be something it can link to.Test plan
See the
ContentsButtonfile