Skip to content
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

Fix nested pressable's event propagation. #2981

Merged
merged 75 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
b911447
add nested pressables example
latekvo Jul 4, 2024
cfc8570
merge 'main'
latekvo Jul 4, 2024
c0af5ec
revert merge artifact
latekvo Jul 4, 2024
40b7691
fix touch propagation for android
latekvo Jul 8, 2024
bc92023
Merge remote-tracking branch 'origin/main' into @latekvo/fix-pressabl…
latekvo Jul 9, 2024
c51602f
Merge branch 'main' into @latekvo/fix-pressable-event-propagation
latekvo Jul 9, 2024
7326626
make use of view built in button to fix propagation on IOS
latekvo Jul 9, 2024
9c5dc56
remove console logs
latekvo Jul 9, 2024
23b93ed
remove unnecessary function call
latekvo Jul 9, 2024
f2e6f77
add hitslop to new view api usage
latekvo Jul 9, 2024
24c1cfc
add support for new events - create and use needed adapters
latekvo Jul 10, 2024
29a5b04
change function names and remove unnecessary exports
latekvo Jul 10, 2024
3df9cdd
simplify function flow
latekvo Jul 10, 2024
c16bbfd
improve variable names
latekvo Jul 10, 2024
acea81d
re-enable native-event related conditions
latekvo Jul 10, 2024
21b8872
rename related type to a more sensible name
latekvo Jul 10, 2024
20d7981
unify types and remove unnecessary type
latekvo Jul 10, 2024
3c448ad
replace unnecessary function
latekvo Jul 10, 2024
67f2a7f
simplify Native View Event adapter
latekvo Jul 10, 2024
0ca146d
fix recursive errors
latekvo Jul 10, 2024
36f4788
clear up variable name
latekvo Jul 10, 2024
509cc1c
remove unnecessary stopPropagation function usage
latekvo Jul 10, 2024
384f5c9
move away from using view touch events
latekvo Jul 10, 2024
bdfed1f
make android example functional again by using Native Gesture for pro…
latekvo Jul 10, 2024
ceda231
fix manual gesture breaking other gestures and write logic for ios ev…
latekvo Jul 10, 2024
bb27ff7
fix long press breaking state flow by removing state-changing gesture…
latekvo Jul 11, 2024
6b49233
correct state flow with correct callback calling on ios and android
latekvo Jul 11, 2024
ce1a4d9
fix functional prop setting on ios
latekvo Jul 11, 2024
7977e14
Merge branch 'main' into @latekvo/fix-pressable-event-propagation
latekvo Jul 11, 2024
b113d32
remove debug messages
latekvo Jul 11, 2024
a514de8
fix double onPressIn calls
latekvo Jul 11, 2024
1b245fa
fix web propagation issue
latekvo Jul 11, 2024
e74b1de
update nested example name
latekvo Jul 11, 2024
91d80a2
fix all gestures randomly being cancelled
latekvo Jul 11, 2024
006c347
remove unnecessary return potentially improving ios responsiveness
latekvo Jul 12, 2024
a1929fc
fix press in being triggered too late on ios outside of native scroll…
latekvo Jul 12, 2024
da5a507
correct major typo in nested example
latekvo Jul 12, 2024
436a2ea
remove unnecessary lorem ipsum
latekvo Jul 12, 2024
eda4915
simplify and improve styles in nested example
latekvo Jul 12, 2024
fe80f48
make all comments upper case
latekvo Jul 12, 2024
9dd8408
make all comments uppercase
latekvo Jul 12, 2024
ae687f4
clarify and remove comments
latekvo Jul 12, 2024
028a18b
remove unnecessary instances of propagationGreenLight
latekvo Jul 12, 2024
5fe2695
fix long press canceling when outside on web
latekvo Jul 12, 2024
8bb2069
change mentions in comments iOS to proper casing
latekvo Jul 12, 2024
a996fbd
fix hover out not working on web
latekvo Jul 12, 2024
41eaf75
fix invalid propagation checks on ios
latekvo Jul 12, 2024
16e5eb1
remove unusual triggerings of nested pressables
latekvo Jul 15, 2024
26d7683
Merge branch 'main' into @latekvo/fix-pressable-event-propagation
latekvo Jul 15, 2024
bb7c3ea
fix incorrect pressOut calls
latekvo Jul 16, 2024
6891168
fix onPress not being called
latekvo Jul 16, 2024
6ed3f46
Merge branch 'main' into @latekvo/fix-pressable-event-propagation
latekvo Jul 16, 2024
e215258
move awaiting event setting to fix lack of onPressIn on ios
latekvo Jul 16, 2024
c5e1903
fix incorrect async concurrency checks resulting in missing callback …
latekvo Jul 17, 2024
e180e85
fix false-positive propagation checks when lightly tapping nested pre…
latekvo Jul 17, 2024
23fd745
add test ids to all nested pressables for ease of testing
latekvo Jul 17, 2024
5d4cbfc
fix propagationGreenLight not being set on ios when native button is …
latekvo Jul 17, 2024
05d51ef
remove unnecessary memo dependancy
latekvo Jul 17, 2024
e307931
remove unnecessary green light disablement
latekvo Jul 17, 2024
2616c6e
change from gesture based to touch based long press
latekvo Jul 17, 2024
94f62dd
add long press timeout clearing
latekvo Jul 17, 2024
e2302c0
add clarification comments to long press gesture
latekvo Jul 17, 2024
884ebcf
add fix for no-scroll no-nesting ios case
latekvo Jul 18, 2024
599f370
fix invalid detection of native gesture as the first gesture
latekvo Jul 18, 2024
0b2749d
clean and remove comments
latekvo Jul 19, 2024
1514a03
flatten if-else trees and remove unused flag
latekvo Jul 19, 2024
3ee32aa
rename variable as per suggestion
latekvo Jul 19, 2024
6f0539d
replace event payload comment for a clearer one
latekvo Jul 19, 2024
3306f1b
update unclear comment
latekvo Jul 19, 2024
be72b2f
change ambiguous ref name
latekvo Jul 22, 2024
6ef4716
remove unnecessary utility function
latekvo Jul 22, 2024
8f3c4a3
improve example design
latekvo Jul 23, 2024
6a21865
change variable name as per suggestion
latekvo Jul 23, 2024
64e9d50
replace inconsistant if statements
latekvo Jul 25, 2024
c7b1b84
rename variable as per suggestion
latekvo Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import MouseButtons from './src/release_tests/mouseButtons';
import ContextMenu from './src/release_tests/contextMenu';
import NestedTouchables from './src/release_tests/nestedTouchables';
import NestedPressables from './src/release_tests/nestedPressables';
import NestedButtons from './src/release_tests/nestedButtons';
import PointerType from './src/release_tests/pointerType';
import SwipeableReanimation from './src/release_tests/swipeableReanimation';
Expand Down Expand Up @@ -130,6 +131,10 @@
name: 'Nested Touchables - issue #784',
component: NestedTouchables as React.ComponentType,
},
{
name: 'Nested Pressables - issue #2980',
component: NestedPressables as React.ComponentType,
},
{
name: 'Nested buttons (sound & ripple on Android)',
component: NestedButtons,
Expand Down Expand Up @@ -266,7 +271,7 @@
renderSectionHeader={({ section: { sectionTitle } }) => (
<Text style={styles.sectionTitle}>{sectionTitle}</Text>
)}
ItemSeparatorComponent={() => <View style={styles.separator} />}

Check warning on line 274 in example/App.tsx

View workflow job for this annotation

GitHub Actions / check (example)

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “MainScreen” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
/>
</SafeAreaView>
);
Expand Down
89 changes: 89 additions & 0 deletions example/src/release_tests/nestedPressables/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React from 'react';
import {
Pressable as LegacyPressable,
PressableStateCallbackType,
StyleProp,
StyleSheet,
Text,
View,
ViewStyle,
} from 'react-native';
import {
ScrollView,
Pressable as GesturizedPressable,
} from 'react-native-gesture-handler';

export default function Example() {
return (
<ScrollView>
<View style={styles.centering}>
<Text style={styles.text}>Gesturized Nested Pressables</Text>
<GesturizedBoxes />
<Text style={styles.text}>Legacy Nested Pressables</Text>
<LegacyBoxes />
</View>
</ScrollView>
);
}

const BOX_SIZE_COEFFICIENT = 100;

const getBoxStyle = (size: number): StyleProp<ViewStyle> => ({
width: size,
height: size,
borderWidth: 1,
});

const innerStyle = ({
pressed,
}: PressableStateCallbackType): StyleProp<ViewStyle> => [
getBoxStyle(BOX_SIZE_COEFFICIENT),
pressed ? { backgroundColor: '#c00' } : { backgroundColor: '#c77' },
styles.centering,
];
const middleStyle = ({
pressed,
}: PressableStateCallbackType): StyleProp<ViewStyle> => [
getBoxStyle(BOX_SIZE_COEFFICIENT * 2),
pressed ? { backgroundColor: '#0c0' } : { backgroundColor: '#7a7' },
styles.centering,
];
const outerStyle = ({
pressed,
}: PressableStateCallbackType): StyleProp<ViewStyle> => [
getBoxStyle(BOX_SIZE_COEFFICIENT * 3),
pressed ? { backgroundColor: '#00c' } : { backgroundColor: '#88a' },
styles.centering,
];

function GesturizedBoxes() {
return (
<GesturizedPressable style={outerStyle} testID="outer">
<GesturizedPressable style={middleStyle} testID="middle">
<GesturizedPressable style={innerStyle} testID="inner" />
</GesturizedPressable>
</GesturizedPressable>
);
}

function LegacyBoxes() {
return (
<LegacyPressable style={outerStyle}>
<LegacyPressable style={middleStyle}>
<LegacyPressable style={innerStyle} />
</LegacyPressable>
</LegacyPressable>
);
}

const styles = StyleSheet.create({
text: {
fontSize: 20,
margin: 20,
},
centering: {
alignItems: 'center',
justifyContent: 'center',
borderRadius: 6,
},
});
Loading
Loading