This repository has been archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
feat: swipe velocity impact as prop #249
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91dd9b1
feat: initial version
osdnk 340708b
fix: snapshots
osdnk 634cc57
Merge branch 'master' into @osdnk/SWI
osdnk b172cc6
feat: expose prop
osdnk 45f251d
fix: vertical gesture
osdnk 5e6d68d
fix: vertical gesture
osdnk 2cd8f2c
fix: drop console.warn
osdnk b798206
refactor: swipeVelocityImpact -> gestureVelocityImpact
osdnk 160339e
fix: tests
osdnk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ type Props = ViewProps & { | |
close: TransitionSpec; | ||
}; | ||
styleInterpolator: CardStyleInterpolator; | ||
gestureVelocityImpact: number; | ||
containerStyle?: StyleProp<ViewStyle>; | ||
contentStyle?: StyleProp<ViewStyle>; | ||
}; | ||
|
@@ -89,7 +90,7 @@ const BOTTOM = 1; | |
const DIRECTION_VERTICAL = -1; | ||
const DIRECTION_HORIZONTAL = 1; | ||
|
||
const SWIPE_VELOCITY_IMPACT = 0.3; | ||
const GESTURE_VELOCITY_IMPACT = 0.3; | ||
|
||
/** | ||
* The distance of touch start from the edge of the screen where the gesture will be recognized | ||
|
@@ -232,10 +233,16 @@ export default class Card extends React.Component<Props> { | |
overlayEnabled: Platform.OS !== 'ios', | ||
shadowEnabled: true, | ||
gestureEnabled: true, | ||
gestureVelocityImpact: GESTURE_VELOCITY_IMPACT, | ||
}; | ||
|
||
componentDidUpdate(prevProps: Props) { | ||
const { layout, gestureDirection, closing } = this.props; | ||
const { | ||
layout, | ||
gestureDirection, | ||
closing, | ||
gestureVelocityImpact, | ||
} = this.props; | ||
const { width, height } = layout; | ||
|
||
if (width !== prevProps.layout.width) { | ||
|
@@ -246,6 +253,10 @@ export default class Card extends React.Component<Props> { | |
this.layout.height.setValue(height); | ||
} | ||
|
||
if (gestureVelocityImpact !== prevProps.gestureVelocityImpact) { | ||
this.gestureVelocityImpact.setValue(gestureVelocityImpact); | ||
} | ||
|
||
if (gestureDirection !== prevProps.gestureDirection) { | ||
this.direction.setValue( | ||
gestureDirection === 'vertical' || | ||
|
@@ -285,6 +296,9 @@ export default class Card extends React.Component<Props> { | |
} | ||
|
||
private isVisible = new Value<Binary>(TRUE); | ||
private gestureVelocityImpact = new Value<number>( | ||
this.props.gestureVelocityImpact | ||
); | ||
private isVisibleValue: Binary = TRUE; | ||
private nextIsVisible = new Value<Binary | -1>(UNSET); | ||
private verticalGestureDirection = new Value( | ||
|
@@ -483,18 +497,19 @@ export default class Card extends React.Component<Props> { | |
|
||
private extrapolatedPosition = add( | ||
this.gesture, | ||
multiply(this.velocity, SWIPE_VELOCITY_IMPACT) | ||
multiply(this.velocity, this.gestureVelocityImpact) | ||
); | ||
|
||
private exec = [ | ||
cond( | ||
eq(this.direction, DIRECTION_HORIZONTAL), | ||
set( | ||
this.gesture, | ||
set( | ||
this.gesture, | ||
cond( | ||
eq(this.direction, DIRECTION_HORIZONTAL), | ||
multiply( | ||
this.gestureUntraversed, | ||
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE | ||
) | ||
), | ||
this.gestureUntraversed | ||
) | ||
), | ||
set( | ||
|
@@ -593,9 +608,13 @@ export default class Card extends React.Component<Props> { | |
cond( | ||
this.distance, | ||
divide( | ||
multiply( | ||
this.gestureUntraversed, | ||
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE | ||
cond( | ||
eq(this.direction, DIRECTION_HORIZONTAL), | ||
multiply( | ||
this.gestureUntraversed, | ||
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE | ||
), | ||
this.gestureUntraversed | ||
Comment on lines
+611
to
+617
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was another bug here. In RTL we were multiplying a gesture in vertical mode as well. |
||
), | ||
this.distance | ||
), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I figured out it's a bug here. We weren't updating
this.gesture
in vertical mode.