-
-
Notifications
You must be signed in to change notification settings - Fork 991
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 Swipeable
misalignment after resizing on web
#3341
Conversation
Swipeable
logic.Swipeable
misalignment after resizing on web
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.
Works well on web 👍
Collapsed reproimport React from 'react';
import { View, Text } from 'react-native';
import Swipeable from 'react-native-gesture-handler/ReanimatedSwipeable';
export default function Example() {
return (
<Swipeable
leftThreshold={50}
rightThreshold={50}
renderLeftActions={() => {
return (
<View style={{ height: 80, width: 80, backgroundColor: 'yellow' }}>
<Text>Left</Text>
</View>
);
}}
renderRightActions={() => {
return (
<View style={{ height: 80, width: 80, backgroundColor: 'magenta' }}>
<Text>Right</Text>
</View>
);
}}>
<View
style={{
height: 80,
backgroundColor: 'blue',
}}
/>
</Swipeable>
);
} |
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.
Starting from this commit, you can no longer open swipeable.
Could you check that @blazejkustra?
Nagranie.z.ekranu.2025-01-20.o.11.46.50.mov
I can confirm that it does not work now: Screen.Recording.2025-01-20.at.12.07.43.mov |
All previous issues should now be fixed since d35e1b3. Collapsed repromake sure to copy
|
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.
Looks ok, please wait till @blazejkustra confirms 😅
Swipeables that don't span 100% of the page width should be fixed since a6536cc. Test code: make sure to copy import React, { useRef } from 'react';
import { View, Text, StyleSheet, I18nManager } from 'react-native';
import Swipeable, {
SwipeableMethods,
} from 'react-native-gesture-handler/ReanimatedSwipeable';
import Animated, {
SharedValue,
useAnimatedStyle,
} from 'react-native-reanimated';
import AppleStyleSwipeableRow from './AppleStyleSwipeableRow';
import GmailStyleSwipeableRow from './GmailStyleSwipeableRow';
import { Pressable, RectButton } from 'react-native-gesture-handler';
// To toggle LTR/RTL change to `true`
I18nManager.allowRTL(false);
function LeftAction(prog: SharedValue<number>, drag: SharedValue<number>) {
const styleAnimation = useAnimatedStyle(() => {
console.log('[R] showLeftProgress:', prog.value);
console.log('[R] appliedTranslation:', drag.value);
return {
transform: [{ translateX: drag.value - 50 }],
};
});
return (
<Animated.View style={styleAnimation}>
<Text style={styles.leftAction}>Text</Text>
</Animated.View>
);
}
function RightAction(prog: SharedValue<number>, drag: SharedValue<number>) {
const styleAnimation = useAnimatedStyle(() => {
console.log('[R] showRightProgress:', prog.value);
console.log('[R] appliedTranslation:', drag.value);
return {
transform: [{ translateX: drag.value + 50 }],
};
});
return (
<Animated.View style={styleAnimation}>
<Text style={styles.rightAction}>Text</Text>
</Animated.View>
);
}
export default function Example() {
const swipeableRef = useRef<SwipeableMethods>(null);
return (
<View style={{ backgroundColor: 'pink' }}>
<View style={styles.controlPanelWrapper}>
<Text>Programatical controls</Text>
<View style={styles.controlPanel}>
<Pressable
style={styles.control}
onPress={() => {
swipeableRef.current!.openLeft();
}}>
<Text>open left</Text>
</Pressable>
<Pressable
style={styles.control}
onPress={() => {
swipeableRef.current!.close();
}}>
<Text>close</Text>
</Pressable>
<Pressable
style={styles.control}
onPress={() => {
swipeableRef.current!.reset();
}}>
<Text>reset</Text>
</Pressable>
<Pressable
style={styles.control}
onPress={() => {
swipeableRef.current!.openRight();
}}>
<Text>open right</Text>
</Pressable>
</View>
</View>
<Swipeable
ref={swipeableRef}
containerStyle={styles.swipeable}
friction={2}
leftThreshold={80}
enableTrackpadTwoFingerGesture
rightThreshold={40}
renderLeftActions={LeftAction}
renderRightActions={RightAction}>
<Text>[Reanimated] Swipe me!</Text>
</Swipeable>
<Swipeable
leftThreshold={50}
rightThreshold={50}
renderLeftActions={() => {
return (
<View style={{ height: 80, width: 80, backgroundColor: 'yellow' }}>
<Text>Left</Text>
</View>
);
}}
renderRightActions={() => {
return (
<View style={{ height: 80, width: 80, backgroundColor: 'magenta' }}>
<Text>Right</Text>
</View>
);
}}>
<View
style={{
height: 80,
backgroundColor: 'blue',
}}
/>
</Swipeable>
<View style={{ marginLeft: 60 }}>
<AppleStyleSwipeableRow>
<RectButton
style={styles.rectButton}
onPress={() => console.log('test-1-center')}>
<Text style={styles.fromText}>Test Center 1</Text>
</RectButton>
</AppleStyleSwipeableRow>
<GmailStyleSwipeableRow>
<RectButton
style={styles.rectButton}
onPress={() => console.log('test-2-center')}>
<Text style={styles.fromText}>Test Center 2</Text>
</RectButton>
</GmailStyleSwipeableRow>
</View>
<View style={{ marginRight: 60 }}>
<AppleStyleSwipeableRow>
<RectButton
style={styles.rectButton}
onPress={() => console.log('test-1-center')}>
<Text style={styles.fromText}>Test Center 1</Text>
</RectButton>
</AppleStyleSwipeableRow>
<GmailStyleSwipeableRow>
<RectButton
style={styles.rectButton}
onPress={() => console.log('test-2-center')}>
<Text style={styles.fromText}>Test Center 2</Text>
</RectButton>
</GmailStyleSwipeableRow>
</View>
<View style={{ marginLeft: 40, marginRight: 40 }}>
<AppleStyleSwipeableRow>
<RectButton
style={styles.rectButton}
onPress={() => console.log('test-1-center')}>
<Text style={styles.fromText}>Test Center 1</Text>
</RectButton>
</AppleStyleSwipeableRow>
<GmailStyleSwipeableRow>
<RectButton
style={styles.rectButton}
onPress={() => console.log('test-2-center')}>
<Text style={styles.fromText}>Test Center 2</Text>
</RectButton>
</GmailStyleSwipeableRow>
</View>
</View>
);
}
const styles = StyleSheet.create({
leftAction: { width: 50, height: 50, backgroundColor: 'crimson' },
rightAction: { width: 50, height: 50, backgroundColor: 'purple' },
rectButton: {
height: 80,
paddingVertical: 10,
paddingHorizontal: 20,
justifyContent: 'space-between',
flexDirection: 'column',
backgroundColor: 'white',
},
separator: {
backgroundColor: 'rgb(200, 199, 204)',
height: StyleSheet.hairlineWidth,
},
fromText: {
fontWeight: 'bold',
backgroundColor: 'transparent',
},
messageText: {
color: '#999',
backgroundColor: 'transparent',
},
dateText: {
backgroundColor: 'transparent',
position: 'absolute',
right: 20,
top: 10,
color: '#999',
fontWeight: 'bold',
},
swipeable: {
height: 50,
backgroundColor: 'papayawhip',
alignItems: 'center',
},
controlPanelWrapper: {
backgroundColor: 'papayawhip',
alignItems: 'center',
},
controlPanel: {
backgroundColor: 'papayawhip',
alignItems: 'center',
flexDirection: 'row',
},
control: {
flex: 1,
height: 40,
borderWidth: StyleSheet.hairlineWidth,
alignItems: 'center',
justifyContent: 'center',
},
}); |
It's working fine now, thanks @latekvo! |
## Description This PR allows Swipeable to be dynamically resized. Fixes #3333 ## Test plan - open any swipeable example on web - resize window - see how the `ReanimatedSwipeable` still works, while the legacy `Swipeable` is misaligned
Description
This PR allows Swipeable to be dynamically resized.
Fixes #3333
Test plan
ReanimatedSwipeable
still works, while the legacySwipeable
is misaligned