Skip to content

Commit 4e57c5c

Browse files
roiberlinInbal-Tish
authored andcommitted
newDrawer - add useNativeAnimations (#469)
* newDrawer - add useNativeAnimations * newDrawer - set default useNativeAnimation to false * newDrawer - remove unnecessary code
1 parent edd5973 commit 4e57c5c

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

src/interactableComponents/drawer/Swipeable.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export default class Swipeable extends Component<PropType, StateType> {
5959
static defaultProps = {
6060
friction: 1,
6161
overshootFriction: 1,
62-
// useNativeAnimations: true // issue in iPhone 5
62+
useNativeAnimations: false // issue in iPhone5
6363
};
64-
64+
6565
_onGestureEvent: ?Animated.Event;
6666
_transX: ?Animated.Interpolation;
6767
_showLeftAction: ?Animated.Interpolation | ?Animated.Value;
@@ -71,7 +71,7 @@ export default class Swipeable extends Component<PropType, StateType> {
7171

7272
constructor(props: PropType) {
7373
super(props);
74-
74+
7575
const dragX = new Animated.Value(0);
7676
this.rowState = 0;
7777

@@ -82,7 +82,7 @@ export default class Swipeable extends Component<PropType, StateType> {
8282
rightOffset: undefined,
8383
rowWidth: Constants.screenWidth
8484
};
85-
85+
8686
this._updateAnimatedEvent(props, this.state);
8787

8888
this._onGestureEvent = Animated.event([{nativeEvent: {translationX: dragX}}], {
@@ -211,18 +211,18 @@ export default class Swipeable extends Component<PropType, StateType> {
211211
_animateRow = (fromValue, toValue, velocityX) => {
212212
const {dragX, rowTranslation} = this.state;
213213
const {
214-
useNativeAnimations,
215-
animationOptions,
216-
onSwipeableLeftOpen,
217-
onSwipeableRightOpen,
218-
onSwipeableClose,
214+
useNativeAnimations,
215+
animationOptions,
216+
onSwipeableLeftOpen,
217+
onSwipeableRightOpen,
218+
onSwipeableClose,
219219
onSwipeableOpen,
220220
onSwipeableLeftWillOpen,
221221
onSwipeableRightWillOpen,
222222
onSwipeableWillClose,
223223
onSwipeableWillOpen
224224
} = this.props;
225-
225+
226226
dragX.setValue(0);
227227
rowTranslation.setValue(fromValue);
228228
this.rowState = Math.sign(toValue);
@@ -268,7 +268,7 @@ export default class Swipeable extends Component<PropType, StateType> {
268268
const {leftWidth = 0, rowWidth = 0} = this.state;
269269
const {rightOffset = rowWidth} = this.state;
270270
const rightWidth = rowWidth - rightOffset;
271-
271+
272272
if (this.rowState === 1) {
273273
return leftWidth;
274274
} else if (this.rowState === -1) {
@@ -311,8 +311,8 @@ export default class Swipeable extends Component<PropType, StateType> {
311311
const left = renderLeftActions && (
312312
<Animated.View
313313
style={[
314-
styles.leftActions,
315-
leftActionsContainerStyle,
314+
styles.leftActions,
315+
leftActionsContainerStyle,
316316
{transform: [{translateX: this._leftActionTranslate}]}
317317
]}
318318
>

src/interactableComponents/drawer/index.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ITEM_PROP_TYPES = {
2626

2727
/**
2828
* @description: Interactable Drawer component
29-
* @extendslink:
29+
* @extendslink:
3030
*/
3131
export default class Drawer extends PureBaseComponent {
3232
static displayName = 'Drawer';
@@ -72,6 +72,10 @@ export default class Drawer extends PureBaseComponent {
7272
* The items' text style
7373
*/
7474
itemsTextStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
75+
/**
76+
* Perform the animation in natively
77+
*/
78+
useNativeAnimations: PropTypes.bool,
7579
};
7680

7781
static defaultProps = {
@@ -95,7 +99,7 @@ export default class Drawer extends PureBaseComponent {
9599
}
96100

97101
UNSAFE_componentWillReceiveProps(nextProps) {
98-
if (JSON.stringify(this.props.leftItem) !== JSON.stringify(nextProps.leftItem) ||
102+
if (JSON.stringify(this.props.leftItem) !== JSON.stringify(nextProps.leftItem) ||
99103
JSON.stringify(this.props.rightItems) !== JSON.stringify(nextProps.rightItems)) {
100104
this.closeDrawer();
101105
}
@@ -178,7 +182,7 @@ export default class Drawer extends PureBaseComponent {
178182
if (_.size(rightItems) > 0) {
179183
const items = rightItems.reverse();
180184
const size = numberOfItems && numberOfItems >= 0 ? numberOfItems : items.length;
181-
185+
182186
for (let i = 0; i < size; i++) {
183187
total += this.getItemWidth(items[i]);
184188
}
@@ -201,21 +205,21 @@ export default class Drawer extends PureBaseComponent {
201205
const rightSpring = equalWidths ? 0 : 30;
202206
const rightWidth = this.getRightItemsTotalWidth();
203207
const rightBound = rightWidth > 0 ? -rightWidth - rightSpring : 0;
204-
208+
205209
return {
206210
right: _.isEmpty(leftItem) ? 0 : leftBound, left: _.isEmpty(rightItems) ? 0 : rightBound};
207211
}
208212
getSnapPoints() {
209213
const {leftItem, rightItems, damping, tension} = this.getThemeProps();
210214
const size = rightItems ? rightItems.length : 0;
211-
215+
212216
const left = !_.isEmpty(leftItem) ? {x: this.getItemWidth(leftItem), damping, tension} : {};
213217
const initial = {x: 0, damping, tension};
214218
const last = rightItems && !_.isEmpty(rightItems[0]) ?
215219
{x: -(this.getRightItemsTotalWidth()), damping, tension} : {};
216220

217221
switch (size) {
218-
case 0:
222+
case 0:
219223
return [left, initial];
220224
default:
221225
return [left, initial, last];
@@ -227,9 +231,9 @@ export default class Drawer extends PureBaseComponent {
227231

228232
const first = {id: 'first', influenceArea: {left: -(this.getRightItemsTotalWidth(1))}};
229233
const second = {id: 'second', influenceArea: {left: -(this.getRightItemsTotalWidth(size - 1))}};
230-
234+
231235
switch (size) {
232-
case 0:
236+
case 0:
233237
case 1:
234238
return [];
235239
case 2:
@@ -243,7 +247,7 @@ export default class Drawer extends PureBaseComponent {
243247
const size = rightItems ? rightItems.length : 0;
244248
const interval = 65;
245249
const inputRanges = [];
246-
250+
247251
for (let i = 0; i < size; i++) {
248252
const itemWidth = this.getItemWidth(rightItems[i]);
249253
const end = itemWidth - (size * BLEED);
@@ -256,13 +260,13 @@ export default class Drawer extends PureBaseComponent {
256260

257261
onLayout = (event) => {
258262
const {width, height} = event.nativeEvent.layout;
259-
263+
260264
const typography = height >= SCALE_POINT ? Typography.text70 : Typography.text80;
261265
const textTopMargin = height > SCALE_POINT ? 8 : 0;
262266
const itemPadding = height >= SCALE_POINT ? ITEM_PADDING : 8;
263-
267+
264268
this.setState({width, height, typography, textTopMargin, itemPadding});
265-
};
269+
};
266270

267271
renderLeftItem() {
268272
const {leftItem, itemsTintColor, itemsIconSize, itemsTextStyle} = this.getThemeProps();
@@ -331,7 +335,7 @@ export default class Drawer extends PureBaseComponent {
331335
]}
332336
{...this.getAnimationConfig()}
333337
/>}
334-
{leftItem && leftItem.text &&
338+
{leftItem && leftItem.text &&
335339
<Animated.Text
336340
numberOfLines={1}
337341
style={
@@ -426,7 +430,7 @@ export default class Drawer extends PureBaseComponent {
426430
]}
427431
{...this.getAnimationConfig()}
428432
/>}
429-
{item.text &&
433+
{item.text &&
430434
<Animated.Text
431435
numberOfLines={1}
432436
style={
@@ -473,7 +477,7 @@ export default class Drawer extends PureBaseComponent {
473477
if (migrate) {
474478
return <NewDrawer ref={this.drawer} {...this.getThemeProps()} />;
475479
}
476-
480+
477481
const {style, onPress, rightItems} = this.getThemeProps();
478482
const Container = onPress ? TouchableOpacity : View;
479483
const backgroundColor = _.get(rightItems, '[0].background', ITEM_BG);
@@ -483,7 +487,7 @@ export default class Drawer extends PureBaseComponent {
483487
<View style={[style, this.styles.container, {backgroundColor}]} onLayout={this.onLayout}>
484488
{rightItems && this.renderRightItems()}
485489
{this.renderLeftItem()}
486-
490+
487491
<Interactable.View
488492
ref={el => (this.interactableElem = el)}
489493
horizontalOnly
@@ -499,15 +503,15 @@ export default class Drawer extends PureBaseComponent {
499503
style={[this.styles.interactable, {width: containerWidth * 2}]}
500504
>
501505
<View style={{backgroundColor: Colors.white}}>
502-
<Container
506+
<Container
503507
style={[this.styles.childrenContainer, {width: containerWidth}]}
504508
activeOpacity={0.7}
505-
onPress={this.onPress}
509+
onPress={this.onPress}
506510
>
507511
{this.props.children}
508512
</Container>
509513
</View>
510-
{rightItems &&
514+
{rightItems &&
511515
<View style={{width: containerWidth, flexDirection: 'row'}}>
512516
{_.map(rightItems, this.renderGhostButton)}
513517
</View>

src/interactableComponents/drawer/newDrawer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class NewDrawer extends PureBaseComponent {
7373
/**
7474
* The items' text style
7575
*/
76-
itemsTextStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number])
76+
itemsTextStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
77+
/**
78+
* Perform the animation in natively
79+
*/
80+
useNativeAnimations: PropTypes.bool,
7781
};
7882

7983
constructor(props) {

0 commit comments

Comments
 (0)