@@ -32,13 +32,17 @@ export enum OpenDirection {
3232
3333const renderNull = ( ) => null ;
3434
35- type VoidPromiseFn = ( ) => Promise < void > ;
36- type OpenPromiseFn = ( snapPoint ?: number ) => Promise < void > ;
35+ type OpenCloseOptions = { animated ?: boolean } ;
36+ type OpenPromiseFn = (
37+ snapPoint ?: number ,
38+ options ?: OpenCloseOptions
39+ ) => Promise < void > ;
40+ type ClosePromiseFn = ( options ?: OpenCloseOptions ) => Promise < void > ;
3741
3842export type UnderlayParams < T > = {
3943 item : T ;
4044 open : OpenPromiseFn ;
41- close : VoidPromiseFn ;
45+ close : ClosePromiseFn ;
4246 percentOpen : Animated . DerivedValue < number > ;
4347 isGestureActive : Animated . DerivedValue < boolean > ;
4448 direction : OpenDirection ;
@@ -48,7 +52,7 @@ export type OverlayParams<T> = {
4852 item : T ;
4953 openLeft : OpenPromiseFn ;
5054 openRight : OpenPromiseFn ;
51- close : VoidPromiseFn ;
55+ close : ClosePromiseFn ;
5256 openDirection : OpenDirection ;
5357 percentOpenLeft : Animated . DerivedValue < number > ;
5458 percentOpenRight : Animated . DerivedValue < number > ;
@@ -81,8 +85,12 @@ type Props<T> = {
8185} ;
8286
8387export type SwipeableItemImperativeRef = {
84- open : ( openDirection : OpenDirection , snapPoint ?: number ) => Promise < void > ;
85- close : ( ) => Promise < void > ;
88+ open : (
89+ openDirection : OpenDirection ,
90+ snapPoint ?: number ,
91+ options ?: OpenCloseOptions
92+ ) => Promise < void > ;
93+ close : ClosePromiseFn ;
8694} ;
8795
8896function SwipeableItem < T > (
@@ -178,60 +186,80 @@ function SwipeableItem<T>(
178186 [ animStatePos ]
179187 ) ;
180188
181- function openLeft ( snapPoint ?: number ) {
189+ const openLeft : OpenPromiseFn = ( snapPoint , options ) => {
182190 return new Promise < void > ( ( resolve ) => {
183191 function resolvePromiseIfFinished ( isFinished : boolean ) {
184192 if ( isFinished ) resolve ( ) ;
185193 }
186- animStatePos . value = withSpring (
187- snapPoint ?? maxSnapPointLeft ,
188- springConfig ,
189- ( isFinished ) => {
194+
195+ const toValue = snapPoint ?? maxSnapPointLeft ;
196+
197+ if ( options ?. animated === false ) {
198+ animStatePos . value = toValue ;
199+ resolve ( ) ;
200+ } else {
201+ animStatePos . value = withSpring ( toValue , springConfig , ( isFinished ) => {
190202 if ( isFinished ) {
191203 runOnJS ( resolvePromiseIfFinished ) ( isFinished ) ;
192204 }
193- }
194- ) ;
205+ } ) ;
206+ }
195207 } ) ;
196- }
197- function openRight ( snapPoint ?: number ) {
208+ } ;
209+
210+ const openRight : OpenPromiseFn = ( snapPoint , options ) => {
198211 return new Promise < void > ( ( resolve ) => {
199212 function resolvePromiseIfFinished ( isFinished : boolean ) {
200213 if ( isFinished ) resolve ( ) ;
201214 }
202- animStatePos . value = withSpring (
203- snapPoint ?? maxSnapPointRight ,
204- springConfig ,
205- ( isFinished ) => {
215+
216+ const toValue = snapPoint ?? maxSnapPointRight ;
217+
218+ if ( options ?. animated === false ) {
219+ animStatePos . value = toValue ;
220+ resolve ( ) ;
221+ } else {
222+ animStatePos . value = withSpring ( toValue , springConfig , ( isFinished ) => {
206223 if ( isFinished ) {
207224 runOnJS ( resolvePromiseIfFinished ) ( isFinished ) ;
208225 }
209- }
210- ) ;
226+ } ) ;
227+ }
211228 } ) ;
212- }
229+ } ;
213230
214- function close ( ) {
231+ const close : ClosePromiseFn = ( options ) => {
215232 return new Promise < void > ( ( resolve ) => {
216233 function resolvePromiseIfFinished ( isFinished : boolean ) {
217234 if ( isFinished ) resolve ( ) ;
218235 }
219- animStatePos . value = withSpring ( 0 , springConfig , ( isFinished ) => {
220- if ( isFinished ) {
221- runOnJS ( resolvePromiseIfFinished ) ( isFinished ) ;
222- }
223- } ) ;
236+
237+ if ( options ?. animated === false ) {
238+ animStatePos . value = 0 ;
239+ resolve ( ) ;
240+ } else {
241+ animStatePos . value = withSpring ( 0 , springConfig , ( isFinished ) => {
242+ if ( isFinished ) {
243+ runOnJS ( resolvePromiseIfFinished ) ( isFinished ) ;
244+ }
245+ } ) ;
246+ }
224247 } ) ;
225- }
248+ } ;
226249
227- useImperativeHandle ( ref , ( ) => ( {
228- open : ( openDirection : OpenDirection , snapPoint ?: number ) => {
229- if ( openDirection === OpenDirection . LEFT ) return openLeft ( snapPoint ) ;
230- if ( openDirection === OpenDirection . RIGHT ) return openRight ( snapPoint ) ;
231- return close ( ) ;
232- } ,
233- close,
234- } ) ) ;
250+ useImperativeHandle ( ref , ( ) => {
251+ const refObject : SwipeableItemImperativeRef = {
252+ open : ( openDirection , snapPoint , options ) => {
253+ if ( openDirection === OpenDirection . LEFT )
254+ return openLeft ( snapPoint , options ) ;
255+ if ( openDirection === OpenDirection . RIGHT )
256+ return openRight ( snapPoint , options ) ;
257+ return close ( ) ;
258+ } ,
259+ close,
260+ } ;
261+ return refObject ;
262+ } ) ;
235263
236264 function onAnimationEnd ( openDirection : OpenDirection , snapPoint : number ) {
237265 setOpenDirection ( openDirection ) ;
0 commit comments