Skip to content

Commit

Permalink
Merge branch 'master' into feature/android-background-image-support
Browse files Browse the repository at this point in the history
  • Loading branch information
ywongweb authored Nov 1, 2017
2 parents a491d32 + da69c6f commit 7c0f956
Show file tree
Hide file tree
Showing 33 changed files with 372 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.reactnativenavigation.animation;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.support.annotation.Nullable;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.view.View;

Expand All @@ -24,12 +27,12 @@ public VisibilityAnimator(View view, HideDirection hideDirection, int height) {
this.hiddenEndValue = hideDirection == HideDirection.Up ? -height : height;
}

public void setVisible(boolean visible, boolean animate) {
public void setVisible(boolean visible, boolean animate, @Nullable Runnable onAnimationEnd) {
cancelAnimator();
if (visible) {
show(animate);
show(animate, onAnimationEnd);
} else {
hide(animate);
hide(animate, onAnimationEnd);
}
}

Expand All @@ -40,31 +43,39 @@ private void cancelAnimator() {
}
}

private void show(boolean animate) {
private void show(boolean animate, @Nullable Runnable onAnimationEnd) {
if (animate) {
animator = createAnimator(true);
animator = createAnimator(true, onAnimationEnd);
animator.start();
} else {
view.setTranslationY(SHOW_END_VALUE);
view.setVisibility(View.VISIBLE);
if (onAnimationEnd != null) onAnimationEnd.run();
}
}

private void hide(boolean animate) {
private void hide(boolean animate, @Nullable Runnable onAnimationEnd) {
if (animate) {
animator = createAnimator(false);
animator = createAnimator(false, onAnimationEnd);
animator.start();
} else {
view.setTranslationY(hiddenEndValue);
view.setVisibility(View.GONE);
if (onAnimationEnd != null) onAnimationEnd.run();
}
}

private ObjectAnimator createAnimator(final boolean show) {
private ObjectAnimator createAnimator(final boolean show, @Nullable final Runnable onAnimationEnd) {
view.setVisibility(View.VISIBLE);
final ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, show ? SHOW_END_VALUE : hiddenEndValue);
animator.setDuration(DURATION);
animator.setInterpolator(interpolator);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (onAnimationEnd != null) onAnimationEnd.run();
}
});
return animator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import com.reactnativenavigation.params.Orientation;
import com.reactnativenavigation.params.ScreenParams;
import com.reactnativenavigation.params.SlidingOverlayParams;
import com.reactnativenavigation.params.StyleParams;
import com.reactnativenavigation.params.TitleBarButtonParams;
import com.reactnativenavigation.params.TitleBarLeftButtonParams;
import com.reactnativenavigation.params.parsers.ModalAnimationFactory;
import com.reactnativenavigation.screens.NavigationType;
import com.reactnativenavigation.utils.StatusBar;

import java.util.List;

Expand Down Expand Up @@ -112,6 +114,14 @@ interface OnModalDismissedListener {
this.screenParams = screenParams;
createContent();
setAnimation(screenParams);
setStatusBarStyle(screenParams.styleParams);
}

private void setStatusBarStyle(StyleParams styleParams) {
Window window = getWindow();
if (window == null) return;
StatusBar.setColor(window, styleParams.statusBarColor);
StatusBar.setTextColorScheme(window.getDecorView(), styleParams.statusBarTextColorScheme);
}

public AppCompatActivity getActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,20 @@ private void destroyJsIfNeeded() {

@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
if (layout != null && !layout.onBackPressed()) {
super.onBackPressed();
}
}

@Override
public void onBackPressed() {
if (layout != null && !layout.onBackPressed()) {
if (layout != null && layout.handleBackInJs()) {
return;
}
if (getReactGateway().isInitialized()) {
getReactGateway().onBackPressed();
} else {
super.onBackPressed();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;

Expand All @@ -31,6 +32,7 @@
import com.reactnativenavigation.screens.NavigationType;
import com.reactnativenavigation.screens.Screen;
import com.reactnativenavigation.screens.ScreenStack;
import com.reactnativenavigation.utils.Task;
import com.reactnativenavigation.utils.ViewUtils;
import com.reactnativenavigation.views.BottomTabs;
import com.reactnativenavigation.views.LightBox;
Expand Down Expand Up @@ -150,7 +152,7 @@ public View asView() {

@Override
public boolean onBackPressed() {
if (getCurrentScreenStack().handleBackPressInJs()) {
if (handleBackInJs()) {
return true;
}

Expand All @@ -164,6 +166,11 @@ public boolean onBackPressed() {
}
}

@Override
public boolean handleBackInJs() {
return getCurrentScreenStack().handleBackPressInJs();
}

@Override
public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
Expand All @@ -172,6 +179,7 @@ public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean an
}

public void setBottomTabsVisible(boolean hidden, boolean animated) {
getCurrentScreenStack().peek().updateBottomTabsVisibility(hidden);
bottomTabs.setVisibility(hidden, animated);
}

Expand Down Expand Up @@ -332,8 +340,13 @@ public void selectBottomTabByTabIndex(Integer index) {
bottomTabs.setCurrentItem(index);
}

public void selectBottomTabByNavigatorId(String navigatorId) {
bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
public void selectBottomTabByNavigatorId(final String navigatorId) {
performOnStack(navigatorId, new Task<ScreenStack>() {
@Override
public void run(ScreenStack param) {
bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
}
});
}

private boolean hasBackgroundColor(StyleParams params) {
Expand All @@ -351,14 +364,18 @@ private void setStyleFromScreen(StyleParams params) {
}

@Override
public void push(ScreenParams params) {
ScreenStack screenStack = getScreenStack(params.getNavigatorId());
screenStack.push(params, createScreenLayoutParams(params));
setStyleFromScreen(params.styleParams);
if (isCurrentStack(screenStack)) {
alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
EventBus.instance.post(new ScreenChangedEvent(params));
}
public void push(final ScreenParams params) {
performOnStack(params.getNavigatorId(), new Task<ScreenStack>() {
@Override
public void run(ScreenStack screenStack) {
screenStack.push(params, createScreenLayoutParams(params));
setStyleFromScreen(params.styleParams);
if (isCurrentStack(screenStack)) {
alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
EventBus.instance.post(new ScreenChangedEvent(params));
}
}
});
}

@Override
Expand Down Expand Up @@ -387,13 +404,17 @@ public void onScreenPopAnimationEnd() {

@Override
public void newStack(final ScreenParams params) {
ScreenStack screenStack = getScreenStack(params.getNavigatorId());
screenStack.newStack(params, createScreenLayoutParams(params));
if (isCurrentStack(screenStack)) {
setStyleFromScreen(params.styleParams);
alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
EventBus.instance.post(new ScreenChangedEvent(params));
}
performOnStack(params.getNavigatorId(), new Task<ScreenStack>() {
@Override
public void run(ScreenStack screenStack) {
screenStack.newStack(params, createScreenLayoutParams(params));
if (isCurrentStack(screenStack)) {
setStyleFromScreen(params.styleParams);
alignSnackbarContainerWithBottomTabs((LayoutParams) snackbarAndFabContainer.getLayoutParams(), params.styleParams);
EventBus.instance.post(new ScreenChangedEvent(params));
}
}
});
}

private void alignSnackbarContainerWithBottomTabs(LayoutParams lp, StyleParams styleParams) {
Expand All @@ -404,6 +425,17 @@ private void alignSnackbarContainerWithBottomTabs(LayoutParams lp, StyleParams s
}
}

private void performOnStack(String navigatorId, Task<ScreenStack> task) {
try {
ScreenStack screenStack = getScreenStack(navigatorId);
task.run(screenStack);
} catch (ScreenStackNotFoundException e) {
Log.e("Navigation", "Could not perform action on stack [" + navigatorId + "]." +
"This should not have happened, it probably means a navigator action" +
"was called from an unmounted tab.");
}
}

@Override
public void destroy() {
snackbarAndFabContainer.destroy();
Expand Down Expand Up @@ -478,7 +510,7 @@ private ScreenStack getCurrentScreenStack() {

private
@NonNull
ScreenStack getScreenStack(String navigatorId) {
ScreenStack getScreenStack(String navigatorId) throws ScreenStackNotFoundException {
int index = getScreenStackIndex(navigatorId);
return screenStacks[index];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface Layout extends ScreenStackContainer {

boolean onBackPressed();

boolean handleBackInJs();

void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated);

void setTitleBarTitle(String screenInstanceId, String title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void createFabAndSnackbarContainer() {

@Override
public boolean onBackPressed() {
if (stack.handleBackPressInJs()) {
if (handleBackInJs()) {
return true;
}

Expand All @@ -122,6 +122,11 @@ public boolean onBackPressed() {
}
}

@Override
public boolean handleBackInJs() {
return stack.handleBackPressInJs();
}

@Override
public void destroy() {
stack.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
public enum StatusBarTextColorScheme {
Light, Dark, Undefined;

public static StatusBarTextColorScheme fromString(@Nullable String colorScheme) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || colorScheme == null) return Undefined;
public static StatusBarTextColorScheme fromString(@Nullable String colorScheme, StatusBarTextColorScheme defaultScheme) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || colorScheme == null) return defaultScheme;
switch (colorScheme) {
case "light":
return Light;
case "dark":
return Dark;
default:
return Undefined;
return defaultScheme;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ public int getColor(int defaultColor) {

public static class Font {
private Typeface typeface;
String fontFamilyName;

public Font(String font) {
fontFamilyName = font;
typeface = new TypefaceLoader(font).getTypeFace();
}

public Font() {
}

public boolean hasFont() {
return typeface != null;
return typeface != null && fontFamilyName != null;
}

public Typeface get() {
Expand All @@ -70,6 +72,11 @@ public Typeface get() {
}
return typeface;
}

@Override
public String toString() {
return fontFamilyName;
}
}

public Orientation orientation;
Expand Down Expand Up @@ -98,6 +105,8 @@ public Typeface get() {
public boolean topBarTranslucent;
public Color titleBarTitleColor;
public Color titleBarSubtitleColor;
public int titleBarSubtitleFontSize;
public Font titleBarSubtitleFontFamily;
public Color titleBarButtonColor;
public Color titleBarDisabledButtonColor;
public Font titleBarTitleFont;
Expand All @@ -106,6 +115,7 @@ public Typeface get() {
public boolean titleBarTitleTextCentered;
public int titleBarHeight;
public boolean backButtonHidden;
public Font titleBarButtonFontFamily;

public Color topTabTextColor;
public Color topTabIconColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TitleBarButtonParams extends BaseTitleBarButtonParams {
@Override
public void setStyleFromScreen(StyleParams styleParams) {
super.setStyleFromScreen(styleParams);
font = styleParams.titleBarTitleFont;
font = styleParams.titleBarButtonFontFamily.hasFont() ? styleParams.titleBarButtonFontFamily : styleParams.titleBarTitleFont;
}

public boolean hasFont() {
Expand Down
Loading

0 comments on commit 7c0f956

Please sign in to comment.