- 
          
- 
                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
          
     Open
      
      
            j-piasecki
  wants to merge
  13
  commits into
  next
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
@jpiasecki/display-contents-button
  
      
      
   
  
    
  
  
  
 
  
      
    base: next
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
                
     Open
            
            
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    c5661d1    to
    fbf37bb      
    Compare
  
    612fb8e    to
    773da37      
    Compare
  
    773da37    to
    d735767      
    Compare
  
    
              
                    m-bert
  
              
              reviewed
              
                  
                    Oct 27, 2025 
                  
              
              
            
            
        
          
                ...act/renderer/components/rngesturehandler_codegen/RNGestureHandlerButtonWrapperShadowNode.cpp
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                ...react/renderer/components/rngesturehandler_codegen/RNGestureHandlerButtonWrapperShadowNode.h
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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