Skip to content

Conversation

@akwasniewski
Copy link
Contributor

Description

After #3634 the Pressable did not work on iOS.
The reason lied in the shadow node of the button wrapper introduced in aforementioned PR which took the layout of the button and instead of changing its own layout to the button's it changed the child view's layout. As a result, the detector got bounds (0,0,0,0) thus all the non-native were considered out of bounds. This broke pressable as it relies on longPress to register touches.

Test plan

Tested on the following code

Details
import React from 'react';
import { Text, StyleSheet, View } from 'react-native';
import { Pressable, GestureHandlerRootView } from 'react-native-gesture-handler'

const PressableExample = () => {
  const [count, setCount] = React.useState(0);
  return (
    <GestureHandlerRootView style={styles.container}>
      <Pressable onPress={() => setCount((c) => c + 1)}>
        <View style={styles.pressable}>
          <Text>{count}</Text>
        </View>
      </Pressable>
    </GestureHandlerRootView >
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  pressable: {
    alignItems: 'center', justifyContent: 'center', backgroundColor: 'green', width: 100, height: 100
  },
  wrapperCustom: {
    borderRadius: 8,
    padding: 16,
    minWidth: 150,
    alignItems: 'center',
  },
  text: {
    fontSize: 18,
    color: 'white',
    fontWeight: '600',
  },
});

export default PressableExample;

Comment on lines +91 to 97
setLayoutMetrics(metrics);

auto metricsNoOrigin = grandChild->getLayoutMetrics();
metricsNoOrigin.frame.origin = Point{};

mutableChild->setLayoutMetrics(metricsNoOrigin);
mutableGrandChild->setLayoutMetrics(metricsNoOrigin);
Copy link
Member

Choose a reason for hiding this comment

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

You also need to handle that in if (shouldSkipCustomLayout) branch above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants