Comments (7)
I created breaks by getting rid of the flick animation and using pure PanResponder and Animation.
(EDIT: For some reason it doesn't like to format my code correctly, so some code may appear out of the code box)
Inside the _onPanResponderRelease(evt, gestureState) function I did the following.
`
//gesture state has negative values for up, so these are less confusing
this.correctedDY = -gestureState.dy;
this.correctedVY = -gestureState.vy;
// BOTTOM PEEK
if(this.currentPosition === this.bottomPeek) {
//user drags/slides up
if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY > 0 ) || this.correctedDY > 50) {
//if user drags over mid break point, go to topbreak
if(this.correctedDY > (this.midBreak - this.bottomPeek + 20)) {
this.transitionTo(this.topBreak, gestureState.vy);
}
else {
this.transitionTo(this.midBreak, gestureState.vy);
}
}
//if user drags/slides down
else if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY < 0 ) || this.correctedDY < -25 ) {
this.transitionTo(this.hidden, gestureState.vy);
//user if closing panel...emit close panel event
EventRegister.emit('closePanel');
}
else {
this.transitionTo(this.bottomPeek, gestureState.vy);
}
}
// MID BREAK
else if(this.currentPosition === this.midBreak) {
//user drags/slides up
if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY > 0 ) || this.correctedDY > 70) {
this.transitionTo(this.topBreak, gestureState.vy);
}
//user drags/slides down
else if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY < 0 ) || this.correctedDY < -50) {
this.transitionTo(this.bottomPeek, gestureState.vy);
}
else {
this.transitionTo(this.midBreak, gestureState.vy);
}
}
// TOP BREAK
else if(this.currentPosition === this.topBreak) {
//if user slides down
if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY < 0) || this.correctedDY < -50) {
//if user drags over mid break point, go to bottomPeak
if(this.correctedDY < -(this.topBreak - this.midBreak + 20)) {
this.transitionTo(this.bottomPeek, gestureState.vy);
}
else {
this.transitionTo(this.midBreak, gestureState.vy);
}
}
else {
this.transitionTo(this.topBreak);
}
}
`
topBreak, midBreak, bottomPeek, and Hidden are just values the slider should transition to
I also changed the transitionTo function slightly to be able to have a initial velocity and to be able to use the Spring animation
`transitionTo(toValue, initialVelocity = 0) {
this.currentPosition = toValue;
return this._triggerAnimation(toValue, initialVelocity)
}
_triggerAnimation(toValue, initialVelocity) {
//if going to topBreak, clamp the animation
const clamping = toValue === this.topBreak ? true : false
const onAnimationEnd = () => {}
const animationConfig = {
bounciness: 10,
velocity: initialVelocity,
overshootClamping: clamping,
toValue: -toValue,
}
const animation = Animated.spring(
this._translateYAnimation,
animationConfig,
)
animation.start(onAnimationEnd)
}`
this.currentPosition
is just a variable I use to track where the panel currently is
from rn-sliding-up-panel.
Thanks for your suggestion @AustinErck. Yes I've thought about it for a while. Will leave this issue open as a reference.
from rn-sliding-up-panel.
It'd be brilliant if this feature was added.
from rn-sliding-up-panel.
Has anyone created this feature?
from rn-sliding-up-panel.
I created breaks by getting rid of the flick animation and using pure PanResponder and Animation.
(EDIT: For some reason it doesn't like to format my code correctly, so some code may appear out of the code box)Inside the _onPanResponderRelease(evt, gestureState) function I did the following.
`//gesture state has negative values for up, so these are less confusing this.correctedDY = -gestureState.dy; this.correctedVY = -gestureState.vy; // BOTTOM PEEK if(this.currentPosition === this.bottomPeek) { //user drags/slides up if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY > 0 ) || this.correctedDY > 50) { //if user drags over mid break point, go to topbreak if(this.correctedDY > (this.midBreak - this.bottomPeek + 20)) { this.transitionTo(this.topBreak, gestureState.vy); } else { this.transitionTo(this.midBreak, gestureState.vy); } } //if user drags/slides down else if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY < 0 ) || this.correctedDY < -25 ) { this.transitionTo(this.hidden, gestureState.vy); //user if closing panel...emit close panel event EventRegister.emit('closePanel'); } else { this.transitionTo(this.bottomPeek, gestureState.vy); } } // MID BREAK else if(this.currentPosition === this.midBreak) { //user drags/slides up if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY > 0 ) || this.correctedDY > 70) { this.transitionTo(this.topBreak, gestureState.vy); } //user drags/slides down else if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY < 0 ) || this.correctedDY < -50) { this.transitionTo(this.bottomPeek, gestureState.vy); } else { this.transitionTo(this.midBreak, gestureState.vy); } } // TOP BREAK else if(this.currentPosition === this.topBreak) { //if user slides down if( (Math.abs(gestureState.vy) > MINIMUM_VELOCITY_THRESHOLD && this.correctedVY < 0) || this.correctedDY < -50) { //if user drags over mid break point, go to bottomPeak if(this.correctedDY < -(this.topBreak - this.midBreak + 20)) { this.transitionTo(this.bottomPeek, gestureState.vy); } else { this.transitionTo(this.midBreak, gestureState.vy); } } else { this.transitionTo(this.topBreak); } }
`
topBreak, midBreak, bottomPeek, and Hidden are just values the slider should transition toI also changed the transitionTo function slightly to be able to have a initial velocity and to be able to use the Spring animation
`transitionTo(toValue, initialVelocity = 0) {
this.currentPosition = toValue;
return this._triggerAnimation(toValue, initialVelocity)
}_triggerAnimation(toValue, initialVelocity) {
//if going to topBreak, clamp the animation const clamping = toValue === this.topBreak ? true : false const onAnimationEnd = () => {} const animationConfig = { bounciness: 10, velocity: initialVelocity, overshootClamping: clamping, toValue: -toValue, } const animation = Animated.spring( this._translateYAnimation, animationConfig, ) animation.start(onAnimationEnd)
}`
this.currentPosition
is just a variable I use to track where the panel currently is
Thank you for this. It has helped my project save some time :)
from rn-sliding-up-panel.
Does anyone have time to update this to work with version 2.0?
from rn-sliding-up-panel.
@epurban I've implemented a snapping method shown in my issue that I recently closed, if you still need it. #102
from rn-sliding-up-panel.
Related Issues (20)
- Maximum call stack on keyboard did show
- Backdrop interaction required HOT 4
- Dissapointed in Android performance HOT 2
- How can implement show(Top) on double click?
- How to fix flatlist on ios
- How to callback any function when onPress on back drop to close panel HOT 1
- undefined is not an object (evaluating 'this._panel.transitionTo')
- How to open() or hide() panel with Redux actions HOT 2
- Theming light and dark mode
- plz convert into hooks
- rn-sliding-up-panel not showing causin javascript bundling fail when opening web
- Not able to use ScrollView inside Panel HOT 1
- Warning: Failed prop type: Invalid prop `children` supplied to `SlidingUpPanel`, expected one of type [function]. HOT 1
- ViewPropTypes has been removed from React Native HOT 1
- PATCH CONSIDERATION - Currently backdrop can't be shown with its touch event disabled
- Dragdown not working while playing audio
- panel size
- Transparent <SlidingUpPanel> gets rendered after a async funtion in a SlidePanel
- DraggableRange bottom does not respect panel show or hide
- Different slide up panels mimic eachother behavior HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rn-sliding-up-panel.