software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.13k stars 982 forks source link

Fix `Pressable` styling by removing unnecessary wrapping `View` #3087

Closed latekvo closed 2 months ago

latekvo commented 2 months ago

Description

This PR removes outer View from Pressable which was previously used for applying props, which were otherwise unavailable on NativeButton.

All such props have been either manually implemented, or have turned out to be available to use directly in NativeButton, so the outer View can be safely removed.

closes #3085

Test plan

Verifying accessibility

note: Most accessibility styles are not implemented on web, but you can verify that accessibility is working on web by inspecting the Pressable and looking for role="button" prop in the HTML, it is an accessibility prop that i found to be working on web.

Code

Collapsed code ```tsx import React from 'react'; import { StyleSheet, Text, View, Pressable as RNPressable } from 'react-native'; import { Pressable as GHPressable, PressableProps, } from 'react-native-gesture-handler'; function Pressables(props: PressableProps) { const onPressInGH = () => console.log('GH press'); const onPressInRN = () => console.log('RN press'); return ( {props.children ?? Gesture Handler!} {props.children ?? React Native!} ); } export default function EmptyExample() { return ( Padding GH nested pressable Gesture Handler RN nested pressable React Native 2 nested pressables GH RN Nested box model styling Hello World! Flex view in a fixed size Pressable Pressable! Flex view in a formless size Pressable Pressable! Standalone pressable Pressable! ); } const styles = StyleSheet.create({ header: { fontSize: 16, fontWeight: 'bold', textAlign: 'center', }, multirow: { flex: 1, flexDirection: 'column', }, container: { flexDirection: 'row', justifyContent: 'space-around', gap: 30, margin: 30, marginTop: 5, }, pressable: { backgroundColor: 'tomato', borderWidth: 1, maxWidth: '30%', }, textWrapper: { flex: 1, justifyContent: 'center', alignItems: 'center', }, }); ```