Skip to content
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

feat(Android): add ios like ios_from_left slide animation #2328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ class Screen(
SLIDE_FROM_LEFT,
FADE_FROM_BOTTOM,
IOS,
IOS_FROM_RIGHT,
IOS_FROM_LEFT,
}

enum class ReplaceAnimation {
Expand Down
12 changes: 9 additions & 3 deletions android/src/main/java/com/swmansion/rnscreens/ScreenStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class ScreenStack(
R.anim.rns_no_animation_medium,
)
StackAnimation.FADE_FROM_BOTTOM -> it.setCustomAnimations(R.anim.rns_fade_from_bottom, R.anim.rns_no_animation_350)
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_slide_in_from_right_ios, R.anim.rns_slide_out_to_left_ios)
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_ios_from_right_foreground_open, R.anim.rns_ios_from_right_background_open)
StackAnimation.IOS_FROM_RIGHT -> it.setCustomAnimations(R.anim.rns_ios_from_right_foreground_open, R.anim.rns_ios_from_right_background_open)
StackAnimation.IOS_FROM_LEFT -> it.setCustomAnimations(R.anim.rns_ios_from_left_foreground_open, R.anim.rns_ios_from_left_background_open)
}
} else {
when (stackAnimation) {
Expand All @@ -183,7 +185,9 @@ class ScreenStack(
R.anim.rns_slide_out_to_bottom,
)
StackAnimation.FADE_FROM_BOTTOM -> it.setCustomAnimations(R.anim.rns_no_animation_250, R.anim.rns_fade_to_bottom)
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_slide_in_from_left_ios, R.anim.rns_slide_out_to_right_ios)
StackAnimation.IOS -> it.setCustomAnimations(R.anim.rns_ios_from_right_foreground_close, R.anim.rns_ios_from_right_background_close)
StackAnimation.IOS_FROM_RIGHT -> it.setCustomAnimations(R.anim.rns_ios_from_right_background_close, R.anim.rns_ios_from_right_foreground_close)
StackAnimation.IOS_FROM_LEFT -> it.setCustomAnimations(R.anim.rns_ios_from_left_background_close, R.anim.rns_ios_from_left_foreground_close)
}
}
}
Expand Down Expand Up @@ -373,6 +377,8 @@ class ScreenStack(
Build.VERSION.SDK_INT >= 33 ||
fragmentWrapper.screen.stackAnimation === StackAnimation.SLIDE_FROM_BOTTOM ||
fragmentWrapper.screen.stackAnimation === StackAnimation.FADE_FROM_BOTTOM ||
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS ||
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS_FROM_RIGHT ||
fragmentWrapper.screen.stackAnimation === StackAnimation.IOS_FROM_LEFT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ open class ScreenViewManager :
"slide_from_bottom" -> Screen.StackAnimation.SLIDE_FROM_BOTTOM
"fade_from_bottom" -> Screen.StackAnimation.FADE_FROM_BOTTOM
"ios" -> Screen.StackAnimation.IOS
"ios_from_right" -> Screen.StackAnimation.IOS_FROM_RIGHT
"ios_from_left" -> Screen.StackAnimation.IOS_FROM_LEFT
else -> throw JSApplicationIllegalArgumentException("Unknown animation type $animation")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="30%"
android:toXDelta="0%" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0%"
android:toXDelta="-30%"/>
android:toXDelta="30%" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:fromXDelta="0%"
android:toXDelta="-100%" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:fromXDelta="-100%"
android:toXDelta="0%" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0%"
android:toXDelta="-30%" />
2 changes: 2 additions & 0 deletions apps/src/screens/Animations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const MainScreen = ({
'slide_from_right',
'slide_from_left',
'ios',
'ios_from_right',
'ios_from_left',
'none',
]}
/>
Expand Down
2 changes: 2 additions & 0 deletions apps/src/screens/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const MainScreen = ({
'slide_from_right',
'slide_from_left',
'ios',
'ios_from_right',
'ios_from_left',
'none',
]}
/>
Expand Down
4 changes: 3 additions & 1 deletion guides/GUIDE_FOR_LIBRARY_AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ Allows for the customization of how the given screen should appear/disappear whe
- `"slide_from_bottom"` - slide in the new screen from bottom to top
- `"slide_from_right"` - slide in the new screen from right to left (Android only, resolves to default transition on iOS)
- `"slide_from_left"` - slide in the new screen from left to right
- `"ios"` - iOS like slide in animation (Android only, resolves to default transition on iOS)
- `"ios"` - @deprecated iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS) (will be removed in v4.0.0 in favor of `ios_from_right`)
- `"ios_from_right"` - iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS)
- `"ios_from_left"` - iOS like slide in animation. pushes in the new screen from left to right (Android only, resolves to default transition on iOS)
- `"none"` – the screen appears/disappears without an animation

### `stackPresentation`
Expand Down
5 changes: 4 additions & 1 deletion ios/RNSConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ + (RNSScreenStackPresentation)RNSScreenStackPresentationFromCppEquivalent:
+ (RNSScreenStackAnimation)RNSScreenStackAnimationFromCppEquivalent:(react::RNSScreenStackAnimation)stackAnimation
{
switch (stackAnimation) {
// these three are intentionally grouped
// these four are intentionally grouped
case react::RNSScreenStackAnimation::Slide_from_right:
case react::RNSScreenStackAnimation::Ios:
case react::RNSScreenStackAnimation::Ios_from_right:
case react::RNSScreenStackAnimation::Default:
return RNSScreenStackAnimationDefault;
// these two are intentionally grouped
case react::RNSScreenStackAnimation::Slide_from_left:
case react::RNSScreenStackAnimation::Ios_from_left:
return RNSScreenStackAnimationSlideFromLeft;
case react::RNSScreenStackAnimation::Flip:
return RNSScreenStackAnimationFlip;
Expand Down
2 changes: 2 additions & 0 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,8 @@ @implementation RCTConvert (RNSScreen)
@"slide_from_right" : @(RNSScreenStackAnimationDefault),
@"slide_from_left" : @(RNSScreenStackAnimationSlideFromLeft),
@"ios" : @(RNSScreenStackAnimationDefault),
@"ios_from_right" : @(RNSScreenStackAnimationDefault),
@"ios_from_left" : @(RNSScreenStackAnimationSlideFromLeft),
}),
RNSScreenStackAnimationDefault,
integerValue)
Expand Down
4 changes: 3 additions & 1 deletion native-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ How the given screen should appear/disappear when pushed or popped at the top of
- `slide_from_bottom` – performs a slide from bottom animation
- `slide_from_right` - slide in the new screen from right to left (Android only, resolves to default transition on iOS)
- `slide_from_left` - slide in the new screen from left to right
- `ios` - iOS like slide in animation (Android only, resolves to default transition on iOS)
- `"ios"` - @deprecated iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS) (will be removed in v4.0.0 in favor of `ios_from_right`)
- `"ios_from_right"` - iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS)
- `"ios_from_left"` - iOS like slide in animation. pushes in the new screen from left to right (Android only, resolves to default transition on iOS)
- `none` - the screen appears/disappears without an animation.

Defaults to `default`.
Expand Down
4 changes: 3 additions & 1 deletion src/fabric/ScreenNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ type StackAnimation =
| 'slide_from_left'
| 'slide_from_bottom'
| 'fade_from_bottom'
| 'ios';
| 'ios'
| 'ios_from_right'
| 'ios_from_left';

type SwipeDirection = 'vertical' | 'horizontal';

Expand Down
4 changes: 3 additions & 1 deletion src/native-stack/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ export type NativeStackNavigationOptions = {
* - "slide_from_bottom" – performs a slide from bottom animation
* - "slide_from_right" - slide in the new screen from right to left (Android only, resolves to default transition on iOS)
* - "slide_from_left" - slide in the new screen from left to right
* - "ios" - iOS like slide in animation (Android only, resolves to default transition on iOS)
* - "ios" - @deprecated iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS) (will be removed in v4.0.0 in favor of `ios_from_right`)
* - "ios_from_right" - iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS)
* - "ios_from_left" - iOS like slide in animation. pushes in the new screen from left to right (Android only, resolves to default transition on iOS)
* - "none" – the screen appears/dissapears without an animation
*/
stackAnimation?: ScreenProps['stackAnimation'];
Expand Down
8 changes: 6 additions & 2 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export type StackAnimationTypes =
| 'slide_from_bottom'
| 'slide_from_right'
| 'slide_from_left'
| 'ios';
| 'ios'
| 'ios_from_right'
| 'ios_from_left';
export type BlurEffectTypes =
| 'extraLight'
| 'light'
Expand Down Expand Up @@ -340,7 +342,9 @@ export interface ScreenProps extends ViewProps {
* - `slide_from_bottom` – performs a slide from bottom animation
* - "slide_from_right" - slide in the new screen from right to left (Android only, resolves to default transition on iOS)
* - "slide_from_left" - slide in the new screen from left to right
* - "ios" - iOS like slide in animation (Android only, resolves to default transition on iOS)
* - "ios" - @deprecated iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS) (will be removed in v4.0.0 in favor of `ios_from_right`)
* - "ios_from_right" - iOS like slide in animation. pushes in the new screen from right to left (Android only, resolves to default transition on iOS)
* - "ios_from_left" - iOS like slide in animation. pushes in the new screen from left to right (Android only, resolves to default transition on iOS)
* - "none" – the screen appears/dissapears without an animation
*/
stackAnimation?: StackAnimationTypes;
Expand Down
4 changes: 3 additions & 1 deletion windows/RNScreens/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ enum class StackAnimation {
SIMPLE_FROM_BOTTOM,
SLIDE_FROM_RIGHT,
SLIDE_FROM_LEFT,
IOS
IOS,
IOS_FROM_RIGHT,
IOS_FROM_LEFT
};

enum class ReplaceAnimation { PUSH, POP };
Expand Down