Skip to content

Commit 6bdb770

Browse files
chrispaderkkafar
authored andcommitted
feat(Android): add ios like ios_from_left slide animation (#2328)
## Description <!-- Description and motivation for this PR. Include Fixes #<number> if this is fixing some issue. Fixes # . --> This PR is based on #1945 and implements the `ios` animation in the reverse direction (slide in from left to right, slide out from right to left) ## Changes <!-- Please describe things you've changed here, make a **high level** overview, if change is simple you can omit this section. For example: - Updated `about.md` docs --> <!-- ## Screenshots / GIFs Here you can add screenshots / GIFs documenting your change. You can add before / after section if you're changing some behavior. ### Before ### After --> ## Test code and steps to reproduce <!-- Please include code that can be used to test this change and short description how this example should work. This snippet should be as minimal as possible and ready to be pasted into editor (don't exclude exports or remove "not important" parts of reproduction example) --> ## Checklist - [x] Included code example that can be used to test this change - [x] Updated TS types - [x] Updated documentation: <!-- For adding new props to native-stack --> - [x] https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md - [x] https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md - [x] https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx - [x] https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx - [x] Ensured that CI passes (cherry picked from commit f80281b)
1 parent f109927 commit 6bdb770

21 files changed

+67
-12
lines changed

android/src/main/java/com/swmansion/rnscreens/Screen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ class Screen(
348348
SLIDE_FROM_LEFT,
349349
FADE_FROM_BOTTOM,
350350
IOS,
351+
IOS_FROM_RIGHT,
352+
IOS_FROM_LEFT,
351353
}
352354

353355
enum class ReplaceAnimation {

android/src/main/java/com/swmansion/rnscreens/ScreenStack.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ class ScreenStack(
160160
R.anim.rns_no_animation_medium,
161161
)
162162
StackAnimation.FADE_FROM_BOTTOM -> it.setCustomAnimations(R.anim.rns_fade_from_bottom, R.anim.rns_no_animation_350)
163-
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_slide_in_from_right_ios, R.anim.rns_slide_out_to_left_ios)
163+
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_ios_from_right_foreground_open, R.anim.rns_ios_from_right_background_open)
164+
StackAnimation.IOS_FROM_RIGHT -> it.setCustomAnimations(R.anim.rns_ios_from_right_foreground_open, R.anim.rns_ios_from_right_background_open)
165+
StackAnimation.IOS_FROM_LEFT -> it.setCustomAnimations(R.anim.rns_ios_from_left_foreground_open, R.anim.rns_ios_from_left_background_open)
164166
}
165167
} else {
166168
when (stackAnimation) {
@@ -183,7 +185,9 @@ class ScreenStack(
183185
R.anim.rns_slide_out_to_bottom,
184186
)
185187
StackAnimation.FADE_FROM_BOTTOM -> it.setCustomAnimations(R.anim.rns_no_animation_250, R.anim.rns_fade_to_bottom)
186-
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_slide_in_from_left_ios, R.anim.rns_slide_out_to_right_ios)
188+
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_ios_from_right_foreground_close, R.anim.rns_ios_from_right_background_close)
189+
StackAnimation.IOS_FROM_RIGHT -> it.setCustomAnimations(R.anim.rns_ios_from_right_background_close, R.anim.rns_ios_from_right_foreground_close)
190+
StackAnimation.IOS_FROM_LEFT -> it.setCustomAnimations(R.anim.rns_ios_from_left_background_close, R.anim.rns_ios_from_left_foreground_close)
187191
}
188192
}
189193
}
@@ -370,6 +374,8 @@ class ScreenStack(
370374
Build.VERSION.SDK_INT >= 33 ||
371375
fragmentWrapper.screen.stackAnimation === StackAnimation.SLIDE_FROM_BOTTOM ||
372376
fragmentWrapper.screen.stackAnimation === StackAnimation.FADE_FROM_BOTTOM ||
373-
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS
377+
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS ||
378+
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS_FROM_RIGHT ||
379+
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS_FROM_LEFT
374380
}
375381
}

android/src/main/java/com/swmansion/rnscreens/ScreenViewManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ open class ScreenViewManager :
103103
"slide_from_bottom" -> Screen.StackAnimation.SLIDE_FROM_BOTTOM
104104
"fade_from_bottom" -> Screen.StackAnimation.FADE_FROM_BOTTOM
105105
"ios" -> Screen.StackAnimation.IOS
106+
"ios_from_right" -> Screen.StackAnimation.IOS_FROM_RIGHT
107+
"ios_from_left" -> Screen.StackAnimation.IOS_FROM_LEFT
106108
else -> throw JSApplicationIllegalArgumentException("Unknown animation type $animation")
107109
}
108110
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="@android:integer/config_shortAnimTime"
4+
android:fromXDelta="30%"
5+
android:toXDelta="0%" />

android/src/main/res/base/anim/rns_slide_out_to_left_ios.xml renamed to android/src/main/res/base/anim/rns_ios_from_left_background_open.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<translate xmlns:android="http://schemas.android.com/apk/res/android"
33
android:duration="@android:integer/config_shortAnimTime"
44
android:fromXDelta="0%"
5-
android:toXDelta="-30%"/>
5+
android:toXDelta="30%" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="@android:integer/config_shortAnimTime"
4+
android:interpolator="@android:interpolator/accelerate_decelerate"
5+
android:fromXDelta="0%"
6+
android:toXDelta="-100%" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="@android:integer/config_shortAnimTime"
4+
android:interpolator="@android:interpolator/accelerate_decelerate"
5+
android:fromXDelta="-100%"
6+
android:toXDelta="0%" />

android/src/main/res/base/anim/rns_slide_in_from_left_ios.xml renamed to android/src/main/res/base/anim/rns_ios_from_right_background_close.xml

File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<translate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="@android:integer/config_shortAnimTime"
4+
android:fromXDelta="0%"
5+
android:toXDelta="-30%" />

android/src/main/res/base/anim/rns_slide_out_to_right_ios.xml renamed to android/src/main/res/base/anim/rns_ios_from_right_foreground_close.xml

File renamed without changes.

0 commit comments

Comments
 (0)