-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cancel showModal animation if back was pressed during animation (#6462)
closes #5245
- Loading branch information
Showing
5 changed files
with
130 additions
and
23 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
lib/android/app/src/main/java/com/reactnativenavigation/utils/AnimationListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.reactnativenavigation.utils | ||
|
||
open class ScreenAnimationListener { | ||
open fun onStart() {} | ||
|
||
open fun onEnd() {} | ||
|
||
open fun onCancel() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...id/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalAnimatorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.reactnativenavigation.viewcontrollers.modal | ||
|
||
import com.nhaarman.mockitokotlin2.* | ||
import com.reactnativenavigation.BaseTest | ||
import com.reactnativenavigation.mocks.SimpleViewController | ||
import com.reactnativenavigation.options.AnimationOptions | ||
import com.reactnativenavigation.options.Options | ||
import com.reactnativenavigation.utils.ScreenAnimationListener | ||
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry | ||
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController | ||
import org.assertj.core.api.Java6Assertions.assertThat | ||
import org.junit.Test | ||
|
||
class ModalAnimatorTest : BaseTest() { | ||
private lateinit var uut: ModalAnimator; | ||
private lateinit var modal1: ViewController<*> | ||
|
||
override fun beforeEach() { | ||
val activity = newActivity() | ||
val childRegistry = mock<ChildControllersRegistry>() | ||
uut = ModalAnimator(activity) | ||
modal1 = SimpleViewController(activity, childRegistry, "child1", Options()) | ||
} | ||
|
||
@Test | ||
fun show_isRunning() { | ||
uut.show(modal1.view, AnimationOptions(), object : ScreenAnimationListener() {}) | ||
assertThat(uut.isRunning).isTrue() | ||
} | ||
|
||
@Test | ||
fun dismiss_dismissModalDuringShowAnimation() { | ||
val showListener = spy<ScreenAnimationListener>() | ||
uut.show(modal1.view, AnimationOptions(), showListener) | ||
|
||
val dismissListener = spy<ScreenAnimationListener>() | ||
uut.dismiss(modal1.view, AnimationOptions(), dismissListener) | ||
|
||
verify(showListener, times(1)).onCancel() | ||
verify(showListener, never()).onEnd() | ||
verify(dismissListener, times(1)).onEnd() | ||
assertThat(uut.isRunning).isFalse() | ||
} | ||
} |