@@ -38,7 +38,7 @@ const {
38
38
} = magic
39
39
40
40
41
- const { set, cond, onChange, block, eq, greaterOrEq, not, defined, max, add, and, Value, spring, or, divide, greaterThan, sub, event, diff, multiply, clockRunning, startClock, stopClock, decay, Clock, lessThan } = Animated
41
+ const { set, cond, onChange, block, eq, greaterOrEq, sqrt , not, defined, max, add, and, Value, spring, or, divide, greaterThan, sub, event, diff, multiply, clockRunning, startClock, stopClock, decay, Clock, lessThan } = Animated
42
42
43
43
44
44
function runDecay ( clock , value , velocity , wasStartedFromBegin ) {
@@ -109,45 +109,14 @@ function withDecaying(drag, state, decayClock, velocity, prevent) {
109
109
] )
110
110
}
111
111
112
- function runSpring ( clock , value , velocity , dest , wasRun = 0 , isManuallySet = 0 ) {
113
- const state = {
114
- finished : new Value ( 0 ) ,
115
- velocity : new Value ( 0 ) ,
116
- position : new Value ( 0 ) ,
117
- time : new Value ( 0 ) ,
118
- }
119
-
120
- const config = {
121
- damping,
122
- mass,
123
- stiffness,
124
- overshootClamping,
125
- restSpeedThreshold,
126
- restDisplacementThreshold,
127
- toValue : new Value ( 0 ) ,
128
- }
129
-
130
- return [
131
- cond ( clockRunning ( clock ) , 0 , [
132
- set ( state . finished , 0 ) ,
133
- set ( state . velocity , velocity ) ,
134
- set ( state . position , value ) ,
135
- set ( config . toValue , dest ) ,
136
- cond ( and ( wasRun , not ( isManuallySet ) ) , 0 , startClock ( clock ) ) ,
137
- cond ( defined ( wasRun ) , set ( wasRun , 1 ) ) ,
138
- ] ) ,
139
- spring ( clock , state , config ) ,
140
- cond ( state . finished , stopClock ( clock ) ) ,
141
- state . position ,
142
- ]
143
- }
144
-
145
112
export default class BottomSheetBehavior extends Component {
146
113
static defaultProps = {
114
+ overdragResistanceFactor : 0 ,
147
115
initialSnap : 0 ,
148
116
enabledImperativeSnapping : true ,
149
117
enabledGestureInteraction : true ,
150
- enabledInnerScrolling : true
118
+ enabledInnerScrolling : true ,
119
+ springConfig : { } ,
151
120
} ;
152
121
153
122
decayClock = new Clock ( ) ;
@@ -197,7 +166,7 @@ export default class BottomSheetBehavior extends Component {
197
166
[
198
167
cond ( this . isManuallySetValue , stopClock ( masterClock ) ) ,
199
168
set ( masterOffseted ,
200
- runSpring ( masterClock , masterOffseted , this . masterVelocity ,
169
+ this . runSpring ( masterClock , masterOffseted , this . masterVelocity ,
201
170
cond ( this . isManuallySetValue , this . manuallySetValue , this . snapPoint ) ,
202
171
wasRun , this . isManuallySetValue )
203
172
) ,
@@ -210,15 +179,21 @@ export default class BottomSheetBehavior extends Component {
210
179
set ( this . preventDecaying , 1 ) ,
211
180
set ( masterOffseted , add ( masterOffseted , sub ( this . dragMasterY , prevMasterDrag ) ) ) ,
212
181
set ( prevMasterDrag , this . dragMasterY ) ,
182
+ set ( wasRun , 0 ) , // not sure about this move for cond-began
213
183
cond ( eq ( this . panMasterState , State . BEGAN ) ,
214
- [
215
- stopClock ( this . masterClockForOverscroll ) ,
216
- set ( wasRun , 0 ) ,
217
- ]
184
+ stopClock ( this . masterClockForOverscroll ) ,
218
185
) ,
219
186
]
220
187
) ,
221
- max ( masterOffseted , snapPoints [ 0 ] )
188
+ cond ( greaterThan ( masterOffseted , snapPoints [ 0 ] ) , masterOffseted ,
189
+ max (
190
+ multiply (
191
+ sub ( snapPoints [ 0 ] , sqrt ( add ( 1 , sub ( snapPoints [ 0 ] , masterOffseted ) ) ) ) ,
192
+ props . overdragResistanceFactor
193
+ ) ,
194
+ masterOffseted
195
+ )
196
+ )
222
197
] )
223
198
224
199
this . Y = this . withEnhancedLimits (
@@ -231,6 +206,40 @@ export default class BottomSheetBehavior extends Component {
231
206
masterOffseted )
232
207
}
233
208
209
+ runSpring ( clock , value , velocity , dest , wasRun = 0 , isManuallySet = 0 ) {
210
+ const state = {
211
+ finished : new Value ( 0 ) ,
212
+ velocity : new Value ( 0 ) ,
213
+ position : new Value ( 0 ) ,
214
+ time : new Value ( 0 ) ,
215
+ }
216
+
217
+ const config = {
218
+ damping,
219
+ mass,
220
+ stiffness,
221
+ overshootClamping,
222
+ restSpeedThreshold,
223
+ restDisplacementThreshold,
224
+ toValue : new Value ( 0 ) ,
225
+ ...this . props . springConfig
226
+ }
227
+
228
+ return [
229
+ cond ( clockRunning ( clock ) , 0 , [
230
+ set ( state . finished , 0 ) ,
231
+ set ( state . velocity , velocity ) ,
232
+ set ( state . position , value ) ,
233
+ set ( config . toValue , dest ) ,
234
+ cond ( and ( wasRun , not ( isManuallySet ) ) , 0 , startClock ( clock ) ) ,
235
+ cond ( defined ( wasRun ) , set ( wasRun , 1 ) ) ,
236
+ ] ) ,
237
+ spring ( clock , state , config ) ,
238
+ cond ( state . finished , stopClock ( clock ) ) ,
239
+ state . position ,
240
+ ]
241
+ }
242
+
234
243
handleMasterPan = event ( [ {
235
244
nativeEvent : ( {
236
245
translationY : this . dragMasterY ,
@@ -292,7 +301,7 @@ export default class BottomSheetBehavior extends Component {
292
301
cond ( and ( eq ( this . panState , State . END ) , not ( wasEndedMasterAfterInner ) , not ( eq ( this . panMasterState , State . ACTIVE ) ) , not ( eq ( this . panMasterState , State . BEGAN ) ) , or ( clockRunning ( this . masterClockForOverscroll ) , not ( wasRunMaster ) ) ) , [
293
302
// cond(justEndedIfEnded, set(this.masterVelocity, diff(val))),
294
303
set ( this . masterVelocity , cond ( justEndedIfEnded , diff ( val ) , this . velocity ) ) ,
295
- set ( masterOffseted , runSpring ( this . masterClockForOverscroll , masterOffseted , diff ( val ) , this . snapPoint , wasRunMaster ) ) ,
304
+ set ( masterOffseted , this . runSpring ( this . masterClockForOverscroll , masterOffseted , diff ( val ) , this . snapPoint , wasRunMaster ) ) ,
296
305
set ( this . masterVelocity , 0 )
297
306
] ) ,
298
307
// cond(eq(this.panState, State.END), set(wasEndedMasterAfterInner, 0)),
@@ -463,8 +472,8 @@ export default class BottomSheetBehavior extends Component {
463
472
< Animated . Code
464
473
exec = { onChange ( this . tapState , cond ( eq ( this . tapState , State . BEGAN ) , stopClock ( this . decayClock ) ) ) } />
465
474
{ this . props . callbackNode &&
466
- < Animated . Code
467
- exec = { onChange ( this . translateMaster , set ( this . props . callbackNode , divide ( this . translateMaster , this . state . snapPoints [ this . state . snapPoints . length - 1 ] ) ) ) } /> }
475
+ < Animated . Code
476
+ exec = { onChange ( this . translateMaster , set ( this . props . callbackNode , divide ( this . translateMaster , this . state . snapPoints [ this . state . snapPoints . length - 1 ] ) ) ) } /> }
468
477
</ View >
469
478
</ Animated . View >
470
479
</ React . Fragment >
0 commit comments