-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/new pan view with reanimated 2 #1404
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b222458
New PanView - somewhat working
M-i-k-e-l 12ea702
Small refactor
M-i-k-e-l 0978cd6
Add worklet
M-i-k-e-l 193fc80
Merge branch 'master' into feat/new-pan-view-with-reanimated-2
M-i-k-e-l faa0207
Fix typings
M-i-k-e-l 700cb59
Do not add GestureHandlerRootView by default
M-i-k-e-l a24f4cf
Move to Incubator
M-i-k-e-l 35d4d54
Move to Incubator (2)
M-i-k-e-l b7a7dbf
Merge branch 'master' into feat/new-pan-view-with-reanimated-2
M-i-k-e-l 03701d8
Add chevronDown to assets and use it from there
M-i-k-e-l 7253810
Rename to PanView...
M-i-k-e-l fa96364
Improve docs
M-i-k-e-l db21282
Add TODO
M-i-k-e-l d1fdd06
Increase damping
M-i-k-e-l 2f3ea15
Reorder imports
M-i-k-e-l dfcfc46
Use Object.assign
M-i-k-e-l 8c4f61e
Move GestureHandlerRootView to the screen
M-i-k-e-l 626044a
Fix tests (import)
M-i-k-e-l b902c33
Remove translationLock
M-i-k-e-l d385d81
Use typeof instead of static types
M-i-k-e-l 9914d42
Remove unused and unecessary styles
M-i-k-e-l a107126
Move default value of directions
M-i-k-e-l 3e49d9e
Add springBack
M-i-k-e-l 82c2c62
Allow returning to the original location
M-i-k-e-l 2af6234
Rename const
M-i-k-e-l 13e7a43
Merge branch 'master' into feat/new-pan-view-with-reanimated-2
M-i-k-e-l 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import React, {Component} from 'react'; | ||
import {StyleSheet, ScrollView} from 'react-native'; | ||
import {GestureHandlerRootView, FlatList} from 'react-native-gesture-handler'; | ||
import { | ||
View, | ||
Text, | ||
Colors, | ||
Incubator, | ||
Card, | ||
Constants, | ||
Modal, | ||
BorderRadiuses, | ||
Image, | ||
TouchableOpacity | ||
} from 'react-native-ui-lib'; | ||
const {PanView} = Incubator; | ||
|
||
interface Item { | ||
value: string; | ||
label: string; | ||
} | ||
|
||
const chevronDown = require('../../assets/icons/chevronDown.png'); | ||
const overlayBackgroundColor = Colors.rgba(Colors.black, 0.2); | ||
const colors: Item[] = [ | ||
{value: Colors.red10, label: 'Red10'}, | ||
{value: Colors.red30, label: 'Red30'}, | ||
{value: Colors.red50, label: 'Red50'}, | ||
{value: Colors.red70, label: 'Red70'}, | ||
{value: Colors.blue10, label: 'Blue10'}, | ||
{value: Colors.blue30, label: 'Blue30'}, | ||
{value: Colors.blue50, label: 'Blue50'}, | ||
{value: Colors.blue70, label: 'Blue70'}, | ||
{value: Colors.purple10, label: 'Purple10'}, | ||
{value: Colors.purple30, label: 'Purple30'}, | ||
{value: Colors.purple50, label: 'Purple50'}, | ||
{value: Colors.purple70, label: 'Purple70'}, | ||
{value: Colors.green10, label: 'Green10'}, | ||
{value: Colors.green30, label: 'Green30'}, | ||
{value: Colors.green50, label: 'Green50'}, | ||
{value: Colors.green70, label: 'Green70'}, | ||
{value: Colors.yellow10, label: 'Yellow10'}, | ||
{value: Colors.yellow30, label: 'Yellow30'}, | ||
{value: Colors.yellow50, label: 'Yellow50'}, | ||
{value: Colors.yellow70, label: 'Yellow70'} | ||
]; | ||
|
||
class PanViewScreen extends Component { | ||
state = { | ||
showToast: false, | ||
showDialog: false | ||
}; | ||
|
||
onDialogDismissed = () => { | ||
this.setState({showDialog: false}); | ||
}; | ||
|
||
keyExtractor = (item: Item) => { | ||
return item.value; | ||
}; | ||
|
||
renderVerticalItem = ({item}: {item: Item}) => { | ||
return ( | ||
<Text text50 margin-20 color={item.value}> | ||
{item.label} | ||
</Text> | ||
); | ||
}; | ||
|
||
renderDialog = () => { | ||
return ( | ||
<View flex> | ||
<Modal | ||
useGestureHandlerRootView | ||
transparent | ||
onBackgroundPress={this.onDialogDismissed} | ||
overlayBackgroundColor={overlayBackgroundColor} | ||
visible | ||
> | ||
<PanView | ||
directions={[PanView.directions.DOWN]} | ||
dismissible | ||
// threshold={{y: 10}} | ||
containerStyle={styles.container} | ||
onDismiss={this.onDialogDismissed} | ||
> | ||
<View style={styles.dialog}> | ||
<Text text60 margin-s2> | ||
Title (swipe here) | ||
</Text> | ||
<View height={1} bg-grey40/> | ||
<FlatList | ||
showsVerticalScrollIndicator={false} | ||
style={styles.verticalScroll} | ||
data={colors} | ||
renderItem={this.renderVerticalItem} | ||
keyExtractor={this.keyExtractor} | ||
/> | ||
</View> | ||
</PanView> | ||
</Modal> | ||
</View> | ||
); | ||
}; | ||
|
||
onToastDismissed = () => { | ||
this.setState({showToast: false}); | ||
}; | ||
|
||
renderToast = () => { | ||
return ( | ||
<PanView | ||
directions={[PanView.directions.LEFT, PanView.directions.DOWN, PanView.directions.RIGHT]} | ||
dismissible | ||
directionLock | ||
threshold={{y: 10}} | ||
containerStyle={styles.container} | ||
onDismiss={this.onToastDismissed} | ||
> | ||
<TouchableOpacity center style={styles.toast} onPress={this.onToastDismissed}> | ||
<Text>Swipe or click to dismiss</Text> | ||
</TouchableOpacity> | ||
</PanView> | ||
); | ||
}; | ||
|
||
renderCard = (key: string, name: string) => { | ||
// @ts-expect-error | ||
const value = this.state[key]; | ||
const text = value ? `I'm still showing or being dismissed` : `Click me (${name})`; | ||
const onPress = value ? undefined : () => this.setState({[key]: true}); | ||
return ( | ||
<Card margin-page onPress={onPress}> | ||
<View padding-15> | ||
<Text text30 grey30> | ||
{text} | ||
</Text> | ||
</View> | ||
</Card> | ||
); | ||
}; | ||
|
||
render() { | ||
const {showToast, showDialog} = this.state; | ||
const Container = showDialog ? View : GestureHandlerRootView; | ||
return ( | ||
<Container style={[styles.root, styles.gestureHandler]}> | ||
<View marginL-page height={50} centerV> | ||
<Text text50>New Pan View</Text> | ||
</View> | ||
<ScrollView> | ||
{this.renderCard('showToast', 'toast')} | ||
{this.renderCard('showDialog', 'dialog')} | ||
<View height={Constants.screenHeight} centerH> | ||
<Text text50 marginB-s2> | ||
Scrollable | ||
</Text> | ||
<Image source={chevronDown}/> | ||
</View> | ||
</ScrollView> | ||
{showToast && this.renderToast()} | ||
{showDialog && this.renderDialog()} | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
export default PanViewScreen; | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
backgroundColor: Colors.grey80 | ||
}, | ||
gestureHandler: { | ||
flex: 1 | ||
}, | ||
container: { | ||
flex: 1, | ||
position: 'absolute', | ||
bottom: 20, | ||
alignSelf: 'center' | ||
}, | ||
toast: { | ||
backgroundColor: Colors.white, | ||
width: 200, | ||
height: 40, | ||
borderRadius: BorderRadiuses.br20, | ||
borderWidth: 0.5, | ||
borderColor: Colors.grey30 | ||
}, | ||
dialog: { | ||
backgroundColor: Colors.white, | ||
width: 200, | ||
height: 300, | ||
borderRadius: BorderRadiuses.br20 | ||
}, | ||
verticalScroll: { | ||
marginTop: 20 | ||
} | ||
}); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { StyleProp, ViewStyle } from 'react-native'; | ||
import { ViewProps } from '../../components/view'; | ||
import { PanningDirections, TranslationLock, PanDismissThreshold } from './panningUtil'; | ||
export { PanningDirections, TranslationLock, PanDismissThreshold }; | ||
export interface PanViewProps extends ViewProps { | ||
/** | ||
* The directions of the allowed pan (default is all) | ||
* Types: UP, DOWN, LEFT and RIGHT (using PanView.directions.###) | ||
*/ | ||
directions?: PanningDirections[]; | ||
/** | ||
* Will enable the dismissible behavior: | ||
* 1. Dismiss if over the threshold. | ||
* 2. Animate to start if no dismissed. | ||
*/ | ||
dismissible?: boolean; | ||
/** | ||
* Callback to the dismiss animation end | ||
*/ | ||
onDismiss?: () => void; | ||
/** | ||
* Should the direction of dragging be locked once a drag has started. | ||
*/ | ||
directionLock?: boolean; | ||
/** | ||
* Allows locking the translation when dragging or dropping. | ||
* i.e. cannot drag back when a certain direction is not allowed. | ||
* Only when dismissible={false} | ||
*/ | ||
translationLock?: TranslationLock; | ||
/** | ||
* Object to adjust the dismiss threshold limits. | ||
*/ | ||
threshold?: PanDismissThreshold; | ||
/** | ||
* Add a style to the container | ||
*/ | ||
containerStyle?: StyleProp<ViewStyle>; | ||
} | ||
interface StaticMembers { | ||
directions: typeof PanningDirections; | ||
translationLock: typeof TranslationLock; | ||
} | ||
declare const _default: React.ComponentClass<PanViewProps & { | ||
useCustomTheme?: boolean | undefined; | ||
}, any> & StaticMembers; | ||
export default _default; |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { PanGestureHandlerEventPayload } from 'react-native-gesture-handler'; | ||
export declare enum PanningDirections { | ||
UP = "up", | ||
DOWN = "down", | ||
LEFT = "left", | ||
RIGHT = "right" | ||
} | ||
export declare enum TranslationLock { | ||
/** | ||
* No locking (default). | ||
*/ | ||
NONE = "none", | ||
/** | ||
* Will lock the start location to the drop location. | ||
* Only when a certain direction is not allowed. | ||
* Only when dismissible={false} | ||
*/ | ||
DROP = "drop", | ||
/** | ||
* Will lock the start location to the dragged location. | ||
* Only when a certain direction is not allowed. | ||
* Only when dismissible={false} | ||
*/ | ||
DRAG = "drag" | ||
} | ||
export interface Frame { | ||
x: number; | ||
y: number; | ||
} | ||
export interface TranslationOptions { | ||
directionLock?: boolean; | ||
translationLock: TranslationLock; | ||
currentTranslation: Frame; | ||
} | ||
export interface PanDismissThreshold { | ||
/** | ||
* The (positive) velocity of a drag\swipe past it the view will be dismissed. | ||
*/ | ||
velocity?: number; | ||
/** | ||
* The x translation from the start location past it the view will be dismissed. | ||
*/ | ||
x?: number; | ||
/** | ||
* The y translation from the start location past it the view will be dismissed. | ||
*/ | ||
y?: number; | ||
} | ||
export declare function getTranslationClamp(initialTranslation: Frame, options: TranslationOptions): Frame; | ||
export declare function getTranslationDirectionClamp(translation: Frame, options: TranslationOptions): Frame; | ||
export declare function getTranslation(event: PanGestureHandlerEventPayload, initialTranslation: Frame, directions: PanningDirections[], options: TranslationOptions): Frame; | ||
export declare const DEFAULT_THRESHOLD: Required<PanDismissThreshold>; | ||
/** | ||
* Will return undefined if should not dismiss | ||
*/ | ||
export declare function getDismissVelocity(event: PanGestureHandlerEventPayload, directions: PanningDirections[], options: TranslationOptions, threshold?: PanDismissThreshold): Partial<Frame> | undefined; |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.