Skip to content
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
4 changes: 4 additions & 0 deletions lib/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ android {
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

allprojects { p ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
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 android.widget.LinearLayout;

import com.reactnativenavigation.views.TopBar;

Expand Down Expand Up @@ -116,15 +116,12 @@ public void animateShowTopBar(final TopBar topBar, final View container) {
ValueAnimator containerHeightAnim = ValueAnimator.ofInt(container.getMeasuredHeight(), container.getMeasuredHeight() - topBar.getMeasuredHeight());
containerHeightAnim.setInterpolator(DECELERATE_INTERPOLATOR);
containerHeightAnim.setDuration(DURATION_TOPBAR);
containerHeightAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) container.getLayoutParams();
layoutParams.height = val;
container.setLayoutParams(layoutParams);
}
});
containerHeightAnim.addUpdateListener(valueAnimator -> {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = container.getLayoutParams();
layoutParams.height = val;
container.setLayoutParams(layoutParams);
});
ObjectAnimator containerTransitionAnim = ObjectAnimator.ofFloat(container, View.TRANSLATION_Y, -1 * topBar.getMeasuredHeight(), 0);
containerTransitionAnim.setInterpolator(DECELERATE_INTERPOLATOR);
containerTransitionAnim.setDuration(DURATION_TOPBAR);
Expand All @@ -142,8 +139,8 @@ public void onAnimationStart(Animator animation) {

@Override
public void onAnimationEnd(Animator animation) {
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) container.getLayoutParams();
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
ViewGroup.LayoutParams layoutParams = container.getLayoutParams();
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
container.setLayoutParams(layoutParams);
}

Expand All @@ -165,15 +162,12 @@ public void animateHideTopBar(final TopBar topBar, final View container) {
ValueAnimator containerHeightAnim = ValueAnimator.ofInt(container.getMeasuredHeight(), container.getMeasuredHeight() + topBar.getMeasuredHeight());
containerHeightAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
containerHeightAnim.setDuration(DURATION_TOPBAR);
containerHeightAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) container.getLayoutParams();
layoutParams.height = val;
container.setLayoutParams(layoutParams);
}
});
containerHeightAnim.addUpdateListener(valueAnimator -> {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = container.getLayoutParams();
layoutParams.height = val;
container.setLayoutParams(layoutParams);
});
ObjectAnimator containerTransitionAnim = ObjectAnimator.ofFloat(container, View.TRANSLATION_Y, 0, -1 * topBar.getMeasuredHeight());
containerTransitionAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
containerTransitionAnim.setDuration(DURATION_TOPBAR);
Expand All @@ -190,8 +184,8 @@ public void onAnimationStart(Animator animation) {

@Override
public void onAnimationEnd(Animator animation) {
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) container.getLayoutParams();
layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
ViewGroup.LayoutParams layoutParams = container.getLayoutParams();
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
container.setLayoutParams(layoutParams);
container.setTranslationY(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import com.reactnativenavigation.viewcontrollers.StackController;
import com.reactnativenavigation.viewcontrollers.ViewController;
import com.reactnativenavigation.viewcontrollers.overlay.DialogViewController;
import com.reactnativenavigation.viewcontrollers.toptabs.TopTabController;
import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsController;
import com.reactnativenavigation.views.ContainerViewCreator;
import com.reactnativenavigation.views.TopTabCreator;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -32,7 +32,7 @@ public LayoutFactory(Activity activity, final ReactInstanceManager reactInstance
public ViewController create(final LayoutNode node) {
switch (node.type) {
case Container:
return createContainer(node, new ContainerViewCreator(reactInstanceManager));
return createContainer(node);
case ContainerStack:
return createContainerStack(node);
case BottomTabs:
Expand All @@ -47,10 +47,10 @@ public ViewController create(final LayoutNode node) {
return createSideMenuRight(node);
case CustomDialog:
return createDialogContainer(node);
case TopTabsContainer:
return createTopTabsContainer(node);
case TopTabs:
return createTopTabs(node);
case TopTab:
return createContainer(node, new TopTabCreator(reactInstanceManager));
return createTopTab(node);
default:
throw new IllegalArgumentException("Invalid node type: " + node.type);
}
Expand Down Expand Up @@ -89,14 +89,14 @@ private ViewController createSideMenuRight(LayoutNode node) {
return create(node.children.get(0));
}

private ViewController createContainer(LayoutNode node, ContainerViewController.ReactViewCreator reactViewCreator) {
private ViewController createContainer(LayoutNode node) {
String id = node.id;
String name = node.data.optString("name");
NavigationOptions navigationOptions = NavigationOptions.parse(node.data.optJSONObject("navigationOptions"), defaultOptions);
return new ContainerViewController(activity,
id,
name,
reactViewCreator,
new ContainerViewCreator(reactInstanceManager),
navigationOptions
);
}
Expand Down Expand Up @@ -126,11 +126,23 @@ private ViewController createDialogContainer(LayoutNode node) {
return new DialogViewController(activity, id, name, creator);
}

private ViewController createTopTabsContainer(LayoutNode node) {
final List<ViewController> tabs = new ArrayList<>();
private ViewController createTopTabs(LayoutNode node) {
final List<TopTabController> tabs = new ArrayList<>();
for (LayoutNode child : node.children) {
tabs.add(create(child));
tabs.add((TopTabController) create(child));
}
return new TopTabsController(activity, node.id, tabs);
}

private ViewController createTopTab(LayoutNode node) {
String id = node.id;
String name = node.data.optString("name");
NavigationOptions navigationOptions = NavigationOptions.parse(node.data.optJSONObject("navigationOptions"), defaultOptions);
return new TopTabController(activity,
id,
name,
new ReactContainerViewCreator(reactInstanceManager),
navigationOptions
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ public enum Type {
SideMenuLeft,
SideMenuRight,
CustomDialog,
TopTabsContainer,
TopTabs,
TopTab
}

public final String id;
public final Type type;
public final JSONObject data;

public final List<LayoutNode> children;
final List<LayoutNode> children;

public LayoutNode(String id, Type type) {
this(id, type, new JSONObject(), new ArrayList<LayoutNode>());
LayoutNode(String id, Type type) {
this(id, type, new JSONObject(), new ArrayList<>());
}

public LayoutNode(String id, Type type, JSONObject data, List<LayoutNode> children) {
LayoutNode(String id, Type type, JSONObject data, List<LayoutNode> children) {
this.id = id;
this.type = type;
this.data = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@
import com.reactnativenavigation.parse.TopBarOptions;
import com.reactnativenavigation.parse.TopTabsOptions;
import com.reactnativenavigation.utils.TypefaceLoader;
import com.reactnativenavigation.viewcontrollers.ContainerViewController;
import com.reactnativenavigation.views.ContainerLayout;
import com.reactnativenavigation.views.TopBar;

public class OptionsPresenter {

private ContainerViewController controller;
private final StackAnimator animator;
private View contentView;
private TopBar topBar;

public OptionsPresenter(ContainerViewController controller) {
this.controller = controller;
animator = new StackAnimator(controller.getActivity());
}
public OptionsPresenter(TopBar topBar, View contentView) {
this.topBar = topBar;
this.contentView = contentView;
animator = new StackAnimator(topBar.getContext());
}

public void applyOptions(NavigationOptions options) {
if (controller != null && controller.getTopBar() != null) {
applyTopBarOptions(options.topBarOptions);
applyTopTabsOptions(options.topTabsOptions);
}
applyTopBarOptions(options.topBarOptions);
applyTopTabsOptions(options.topTabsOptions);
}

private void applyTopBarOptions(TopBarOptions options) {
controller.setTitle(options.title);
controller.setBackgroundColor(options.backgroundColor);
controller.setTitleTextColor(options.textColor);
controller.setTitleFontSize(options.textFontSize);
topBar.setTitle(options.title);
topBar.setBackgroundColor(options.backgroundColor);
topBar.setTitleTextColor(options.textColor);
topBar.setTitleFontSize(options.textFontSize);

TypefaceLoader typefaceLoader = new TypefaceLoader();
controller.getTopBar().setTitleTypeface(typefaceLoader.getTypeFace(controller.getActivity(), options.textFontFamily));
topBar.setTitleTypeface(typefaceLoader.getTypeFace(topBar.getContext(), options.textFontFamily));
if (options.hidden == NavigationOptions.BooleanOptions.True) {
hideTopBar(options.animateHide);
}
Expand All @@ -43,26 +43,24 @@ private void applyTopBarOptions(TopBarOptions options) {
}

private void showTopBar(NavigationOptions.BooleanOptions animated) {
if (controller.getTopBar().getVisibility() == View.VISIBLE) {
if (topBar.getVisibility() == View.VISIBLE) {
return;
}
if (animated == NavigationOptions.BooleanOptions.True) {
ContainerLayout topBarContainerView = (ContainerLayout) controller.getContainerView();
animator.animateShowTopBar(controller.getTopBar(), topBarContainerView.getReactView().asView());
animator.animateShowTopBar(topBar, contentView);
} else {
controller.getTopBar().setVisibility(View.VISIBLE);
topBar.setVisibility(View.VISIBLE);
}
}

private void hideTopBar(NavigationOptions.BooleanOptions animated) {
if (controller.getTopBar().getVisibility() == View.GONE) {
if (topBar.getVisibility() == View.GONE) {
return;
}
if (animated == NavigationOptions.BooleanOptions.True) {
ContainerLayout topBarContainerView = (ContainerLayout) controller.getContainerView();
animator.animateHideTopBar(controller.getTopBar(), topBarContainerView.getReactView().asView());
animator.animateHideTopBar(topBar, contentView);
} else {
controller.getTopBar().setVisibility(View.GONE);
topBar.setVisibility(View.GONE);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.reactnativenavigation.utils;

public interface Task<T> {
void run(T param);
}
Loading