Skip to content

Commit 4ce92eb

Browse files
authored
Drawer - trigger onToggleSwipeLeft on releases (#860)
* trigger onToggleSwipeLeft on releases * Changing animation's easing * bug fix * renaming variable * fix example * fix example 2
1 parent 63e9377 commit 4ce92eb

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

demo/src/screens/componentScreens/DrawerScreen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class DrawerScreen extends Component {
184184
centerV
185185
style={{borderBottomWidth: 1, borderColor: Colors.grey60}}
186186
>
187-
{this.state.unread && <Badge size={'pimpleBig'} backgroundColor={Colors.purple30} containerStyle={{marginRight: 8}}/>}
187+
{this.state.unread && <Badge size={'pimpleSmall'} backgroundColor={Colors.red30} containerStyle={{marginRight: 8}}/>}
188188
<Avatar source={{uri: conversations[0].thumbnail}}/>
189189
<View marginL-20>
190190
<Text text70R={!this.state.unread} text70BO={this.state.unread}>{conversations[0].name}</Text>
@@ -226,9 +226,9 @@ class DrawerScreen extends Component {
226226

227227
if (showLeftItem) {
228228
drawerProps.leftItem = {
229-
icon: require('../../assets/icons/mail.png'),
230-
text: this.state.unread ? 'Read' : 'Unread',
231-
background: this.state.unread ? Colors.green30 : Colors.purple30,
229+
icon: this.state.unread ? require('../../assets/icons/mail.png') : require('../../assets/icons/refresh.png'),
230+
text: !this.state.unread ? 'Unread' : 'Read',
231+
background: this.state.unread ? Colors.green30 : Colors.orange30,
232232
onPress: this.toggleReadState
233233
};
234234
}

src/components/drawer/Swipeable.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default class Swipeable extends Component<PropType, StateType> {
9090
// 1 -> closing to the left
9191
// -1 -> closing to the right
9292
this.rowState = 0;
93-
this.dragFired = false;
93+
this.dragThresholdReached = false;
9494

9595
this.state = {
9696
dragX,
@@ -112,12 +112,12 @@ export default class Swipeable extends Component<PropType, StateType> {
112112
_handleDrag = (e) => {
113113
const {onToggleSwipeLeft} = this.props;
114114

115-
if (onToggleSwipeLeft && !this.dragFired) {
115+
if (onToggleSwipeLeft && !this.dragThresholdReached) {
116116
const {rowWidth, leftWidth} = this.state;
117117
const x = e.nativeEvent.translationX;
118118
const threshold = rowWidth * LEFT_TOGGLE_THRESHOLD;
119119
if (x >= threshold && x < threshold + 10) {
120-
this.dragFired = true;
120+
this.dragThresholdReached = true;
121121
onToggleSwipeLeft({rowWidth, leftWidth, dragX: x});
122122
}
123123
}
@@ -223,7 +223,7 @@ export default class Swipeable extends Component<PropType, StateType> {
223223
let toValue = 0;
224224
if (this.rowState === 0) {
225225
if (onToggleSwipeLeft && translationX > leftWidth) {
226-
if (!this.dragFired) {
226+
if (!this.dragThresholdReached) {
227227
toValue = rowWidth * LEFT_TOGGLE_THRESHOLD;
228228
}
229229
} else if (fullSwipeLeft && translationX > rowWidth * fullLeftThreshold) {
@@ -303,8 +303,8 @@ export default class Swipeable extends Component<PropType, StateType> {
303303
}
304304
});
305305

306-
if (toValue === rowWidth * LEFT_TOGGLE_THRESHOLD && onToggleSwipeLeft) {
307-
onToggleSwipeLeft({rowWidth, leftWidth});
306+
if ((toValue === rowWidth * LEFT_TOGGLE_THRESHOLD || this.dragThresholdReached) && onToggleSwipeLeft) {
307+
onToggleSwipeLeft({rowWidth, leftWidth, released: true});
308308
} else if (toValue === rowWidth && onWillFullSwipeLeft) {
309309
onWillFullSwipeLeft()
310310
} else if (toValue === -rowWidth && onWillFullSwipeRight) {

src/components/drawer/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ class NewDrawer extends PureBaseComponent {
187187
_.invoke(this.props, 'onSwipeableWillClose', this.props);
188188
};
189189

190-
onToggleSwipeLeft = ({rowWidth, leftWidth, dragX}) => {
190+
onToggleSwipeLeft = ({rowWidth, leftWidth, dragX, released}) => {
191191
Animated.timing(this.leftActionX, {
192192
toValue: dragX ? dragX - leftWidth : rowWidth * 0.6 - leftWidth,
193-
easing: Easing.linear,
194-
duration: 100,
193+
easing: Easing.bezier(0.25, 1, 0.5, 1),
194+
duration: 200,
195195
delay: 100,
196196
useNativeDriver: true
197-
}).start(this.toggle());
197+
}).start(released && this.toggle());
198198
}
199199

200200
toggle() {
@@ -343,7 +343,7 @@ class NewDrawer extends PureBaseComponent {
343343
};
344344

345345
render() {
346-
const {children, style, leftItem, rightItems, ...others} = this.getThemeProps();
346+
const {children, style, leftItem, rightItems, onToggleSwipeLeft, ...others} = this.getThemeProps();
347347

348348
return (
349349
<Swipeable
@@ -358,7 +358,7 @@ class NewDrawer extends PureBaseComponent {
358358
leftActionsContainerStyle={this.getLeftActionsContainerStyle(leftItem, rightItems)}
359359
onSwipeableWillOpen={this.onSwipeableWillOpen}
360360
onSwipeableWillClose={this.onSwipeableWillClose}
361-
onToggleSwipeLeft={this.onToggleSwipeLeft}
361+
onToggleSwipeLeft={onToggleSwipeLeft && this.onToggleSwipeLeft}
362362
>
363363
<View
364364
// flex

0 commit comments

Comments
 (0)