Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ad2dce8
readme
Cool04ek Dec 5, 2017
929f7d9
merge
Cool04ek Dec 19, 2017
47df89b
doc
Cool04ek Dec 20, 2017
b55c450
topbar fix
Cool04ek Dec 20, 2017
2e815f0
rm doc
Cool04ek Dec 20, 2017
dc739e5
Merge branch 'v2' into topbar
guyca Dec 20, 2017
51489d0
Merge branch 'v2' into topbar
guyca Dec 20, 2017
ac0e9df
options presenter fix
Cool04ek Dec 20, 2017
e3f3316
Merge branch 'topbar' of github.com:wix/react-native-navigation into …
Cool04ek Dec 20, 2017
e4f534a
rm userless stuff
Cool04ek Dec 20, 2017
44c2813
WIP
Cool04ek Dec 22, 2017
f3d26b9
WIP
Cool04ek Dec 26, 2017
ccd2170
WIP
Cool04ek Dec 26, 2017
a2c9101
translation
Cool04ek Dec 26, 2017
3a94214
WIP
Cool04ek Dec 27, 2017
e53a34e
todo
Cool04ek Dec 27, 2017
918981b
draw under
Cool04ek Dec 27, 2017
5e3dc19
merge
Cool04ek Jan 4, 2018
9857169
fix merge
Cool04ek Jan 4, 2018
0bd6e12
merge fix
Cool04ek Jan 4, 2018
894c643
more merge fix
Cool04ek Jan 4, 2018
374272f
improve calc
Cool04ek Jan 4, 2018
e124037
animation improvement
Cool04ek Jan 4, 2018
7339006
fix tests
Cool04ek Jan 5, 2018
68e8299
refactor
Cool04ek Jan 5, 2018
59193ad
refctor
Cool04ek Jan 5, 2018
cd3c10d
tests
Cool04ek Jan 7, 2018
ecf0c43
merge v2
Cool04ek Jan 7, 2018
98ef654
fix test
Cool04ek Jan 7, 2018
702d1ec
anim improve
Cool04ek Jan 7, 2018
ccf545f
rm outdated
Cool04ek Jan 8, 2018
0ea0d2b
refactoring
Cool04ek Jan 8, 2018
b085972
more refactoring
Cool04ek Jan 8, 2018
f27bfd6
tests
Cool04ek Jan 8, 2018
44478ca
refactor
Cool04ek Jan 8, 2018
3a377a4
hotfix
Cool04ek Jan 8, 2018
bf7575f
more refactoring
Cool04ek Jan 8, 2018
726900e
refactor
Cool04ek Jan 9, 2018
4002f48
some more refactoring
Cool04ek Jan 9, 2018
cf6a0e7
refactor
Cool04ek Jan 9, 2018
66014ef
Merge branch 'v2' into topbar
Cool04ek Jan 9, 2018
e379be1
Collapse topbar
Cool04ek Jan 9, 2018
799ad30
Merge branch 'v2' into topbar
Cool04ek Jan 9, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,94 +15,100 @@

@RunWith(AndroidJUnit4.class)
public abstract class BaseTest {
static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
private static final long TIMEOUT = 60000;

@Before
public void beforeEach() throws Exception {
device().wakeUp();
device().setOrientationNatural();
launchTheApp();
assertMainShown();
}

@After
public void afterEach() throws Exception {
device().executeShellCommand("am force-stop " + PACKAGE_NAME);
device().executeShellCommand("am kill " + PACKAGE_NAME);
}

public UiDevice device() {
return UiDevice.getInstance(getInstrumentation());
}

public void launchTheApp() throws Exception {
device().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
device().waitForIdle();
acceptOverlayPermissionIfNeeded();
device().wait(Until.gone(By.textContains("Please wait")), 1000 * 60 * 3);
}

public void assertMainShown() {
assertExists(By.text("React Native Navigation!"));
}

public void acceptOverlayPermissionIfNeeded() throws Exception {
if (isRequestingOverlayPermission()) {
if (!elementByText("Playground").exists()) {
scrollToText("Playground");
}
elementByText("Playground").click();
device().findObject(new UiSelector().checkable(true).checked(false)).click();
device().pressBack();
device().pressBack();
}
}

private boolean isRequestingOverlayPermission() {
return device().wait(Until.hasObject(By.pkg("com.android.settings").depth(0)), 300);
}

public UiObject elementByText(String text) {
return device().findObject(new UiSelector().text(text));
}

public UiObject elementByTextContains(String text) {
return device().findObject(new UiSelector().textContains(text));
}

public void scrollToText(String txt) throws Exception {
new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
}

public void assertExists(BySelector selector) {
assertThat(device().wait(Until.hasObject(selector), TIMEOUT)).withFailMessage("expected %1$s to be visible", selector).isTrue();
assertThat(device().findObject(selector).getVisibleCenter().x).isPositive().isLessThan(device().getDisplayWidth());
assertThat(device().findObject(selector).getVisibleCenter().y).isPositive().isLessThan(device().getDisplayHeight());
}

public Bitmap captureScreenshot() throws Exception {
File file = File.createTempFile("tmpE2E", "png");
device().takeScreenshot(file);
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
file.delete();
return bitmap;
}

public void swipeOpenFromLeft() {
int w = device().getDisplayWidth();
int h = device().getDisplayHeight();
device().swipe(5, h / 2, w / 2, h / 2, 10);
}

public void swipeOpenFromRight() {
int w = device().getDisplayWidth();
int h = device().getDisplayHeight();
device().swipe(w - 5, h / 2, w / 2, h / 2, 10);
}

public boolean isDebug() throws Exception {
PackageInfo packageInfo = getInstrumentation().getTargetContext().getPackageManager().getPackageInfo("com.reactnativenavigation.playground", 0);
return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
static final String PACKAGE_NAME = "com.reactnativenavigation.playground";
private static final long TIMEOUT = 60000;

@Before
public void beforeEach() throws Exception {
device().wakeUp();
device().setOrientationNatural();
launchTheApp();
assertMainShown();
}

@After
public void afterEach() throws Exception {
device().executeShellCommand("am force-stop " + PACKAGE_NAME);
device().executeShellCommand("am kill " + PACKAGE_NAME);
}

public UiDevice device() {
return UiDevice.getInstance(getInstrumentation());
}

public void launchTheApp() throws Exception {
device().executeShellCommand("am start -n " + PACKAGE_NAME + "/.MainActivity");
device().waitForIdle();
acceptOverlayPermissionIfNeeded();
device().wait(Until.gone(By.textContains("Please wait")), 1000 * 60 * 3);
}

public void assertMainShown() {
assertExists(By.text("React Native Navigation!"));
}

public void acceptOverlayPermissionIfNeeded() throws Exception {
if (isRequestingOverlayPermission()) {
if (!elementByText("Playground").exists()) {
scrollToText("Playground");
}
elementByText("Playground").click();
device().findObject(new UiSelector().checkable(true).checked(false)).click();
device().pressBack();
device().pressBack();
}
}

private boolean isRequestingOverlayPermission() {
return device().wait(Until.hasObject(By.pkg("com.android.settings").depth(0)), 300);
}

public UiObject elementByText(String text) {
return device().findObject(new UiSelector().text(text));
}

public UiObject elementByTextContains(String text) {
return device().findObject(new UiSelector().textContains(text));
}

public void scrollToText(String txt) throws Exception {
new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView(txt);
}

public void assertExists(BySelector selector) {
assertThat(device().wait(Until.hasObject(selector), TIMEOUT)).withFailMessage("expected %1$s to be visible", selector).isTrue();
assertThat(device().findObject(selector).getVisibleCenter().x).isPositive().isLessThan(device().getDisplayWidth());
assertThat(device().findObject(selector).getVisibleCenter().y).isPositive().isLessThan(device().getDisplayHeight());
}

public Bitmap captureScreenshot() throws Exception {
File file = File.createTempFile("tmpE2E", "png");
device().takeScreenshot(file);
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
file.delete();
return bitmap;
}

public void swipeOpenFromLeft() {
int w = device().getDisplayWidth();
int h = device().getDisplayHeight();
device().swipe(5, h / 2, w / 2, h / 2, 10);
}

public void swipeOpenFromRight() {
int w = device().getDisplayWidth();
int h = device().getDisplayHeight();
device().swipe(w - 5, h / 2, w / 2, h / 2, 10);
}

public void swipeUp() {
int w = device().getDisplayWidth();
int h = device().getDisplayHeight();
device().drag(w / 2, h / 2 + 100, w / 2, h / 2 - 100, 10);
}

public boolean isDebug() throws Exception {
PackageInfo packageInfo = getInstrumentation().getTargetContext().getPackageManager().getPackageInfo("com.reactnativenavigation.playground", 0);
return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
package com.reactnativenavigation.e2e.androide2e;

import android.support.test.uiautomator.By;
import android.support.test.uiautomator.Until;

import org.junit.Test;

import static org.assertj.core.api.Java6Assertions.assertThat;

public class NavigationOptionsTest extends BaseTest {

@Test
public void declareNavigationStyleOnContainerComponent() throws Exception {
elementByText("PUSH OPTIONS SCREEN").click();
assertExists(By.text("Static Title"));
}

@Test
public void setTitleDynamically() throws Exception {
elementByText("PUSH OPTIONS SCREEN").click();
assertExists(By.text("Static Title"));
elementByText("DYNAMIC OPTIONS").click();
assertExists(By.text("Dynamic Title"));
}

// @Test
// public void testTopBarHidden() throws Exception {
// elementByText("PUSH OPTIONS SCREEN").click();
// int topWithNavigation = elementByText("HIDE TOP BAR").getVisibleBounds().top;
// elementByText("HIDE TOP BAR").click();
// int topWithoutNavigation = elementByText("HIDE TOP BAR").getVisibleBounds().top;
// assertThat(topWithoutNavigation).isLessThan(topWithNavigation);
// elementByText("SHOW TOP BAR").click();
// assertExists(By.text("Static Title"));
// }
@Test
public void declareNavigationStyleOnContainerComponent() throws Exception {
elementByText("PUSH OPTIONS SCREEN").click();
assertExists(By.text("Static Title"));
}

@Test
public void setTitleDynamically() throws Exception {
elementByText("PUSH OPTIONS SCREEN").click();
assertExists(By.text("Static Title"));
elementByText("DYNAMIC OPTIONS").click();
assertExists(By.text("Dynamic Title"));
}

@Test
public void testTopBarHidden() throws Exception {
elementByText("PUSH OPTIONS SCREEN").click();
int topWithNavigation = elementByText("HIDE TOP BAR").getVisibleBounds().top;
elementByText("HIDE TOP BAR").click();
int topWithoutNavigation = elementByText("HIDE TOP BAR").getVisibleBounds().top;
assertThat(topWithoutNavigation).isLessThan(topWithNavigation);
elementByText("SHOW TOP BAR").click();
assertExists(By.text("Static Title"));
}

@Test
public void testRightButtons() throws Exception {
elementByText("PUSH OPTIONS SCREEN").click();
assertExists(By.text("ONE"));
elementByText("ONE").click();
}

@Test
public void testTopBarCollapse() throws Exception {
elementByText("PUSH OPTIONS SCREEN").click();
elementByText("SCROLLVIEW SCREEN").click();
assertExists(By.text("Collapse"));
elementByText("TOGGLE TOP BAR HIDE ON SCROLL").click();
swipeUp();
assertThat(device().hasObject(By.text("Collapse"))).isFalse();
}
}
2 changes: 1 addition & 1 deletion lib/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ dependencies {
testImplementation 'org.robolectric:robolectric:3.5.1'
testImplementation 'org.assertj:assertj-core:3.8.0'
testImplementation 'com.squareup.assertj:assertj-android:1.1.1'
testImplementation 'org.mockito:mockito-core:2.12.0'
testImplementation 'org.mockito:mockito-core:2.13.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.reactnativenavigation.anim;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

import com.reactnativenavigation.utils.UiUtils;
import com.reactnativenavigation.views.TopBar;

@SuppressWarnings("ResourceType")
public class NavigationAnimator {

public interface NavigationAnimationListener {
void onAnimationEnd();
}

private static final int DURATION = 300;
private static final DecelerateInterpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator();
private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();
private float translationY;

public NavigationAnimator(Context context) {
translationY = UiUtils.getWindowHeight(context);
}

public void animatePush(final View view, @Nullable final NavigationAnimationListener animationListener) {
view.setVisibility(View.INVISIBLE);
ObjectAnimator alpha = ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1);
alpha.setInterpolator(DECELERATE_INTERPOLATOR);

AnimatorSet set = new AnimatorSet();
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
view.setVisibility(View.VISIBLE);
}

@Override
public void onAnimationEnd(Animator animation) {
if (animationListener != null) {
animationListener.onAnimationEnd();
}
}
});
ObjectAnimator translationY = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, this.translationY, 0);
translationY.setInterpolator(DECELERATE_INTERPOLATOR);
translationY.setDuration(DURATION);
alpha.setDuration(DURATION);
set.playTogether(translationY, alpha);
set.start();
}

public void animatePop(View view, @Nullable final NavigationAnimationListener animationListener) {
ObjectAnimator alpha = ObjectAnimator.ofFloat(view, View.ALPHA, 1, 0);
alpha.setInterpolator(ACCELERATE_INTERPOLATOR);

AnimatorSet set = new AnimatorSet();
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animationListener != null) {
animationListener.onAnimationEnd();
}
}
});
ObjectAnimator translationY = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, 0, this.translationY);
translationY.setInterpolator(ACCELERATE_INTERPOLATOR);
translationY.setDuration(DURATION);
alpha.setDuration(DURATION);
set.playTogether(translationY, alpha);
set.start();
}
}
Loading