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

Merge SideMenuController options with parent #5754

Merged
merged 3 commits into from
Dec 10, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
import static com.reactnativenavigation.utils.CollectionUtils.*;
import static com.reactnativenavigation.utils.ObjectUtils.perform;

public abstract class ParentController<T extends ViewGroup> extends ChildController {
public abstract class ParentController<T extends ViewGroup> extends ChildController<T> {

public ParentController(Activity activity, ChildControllersRegistry childRegistry, String id, Presenter presenter, Options initialOptions) {
public ParentController(Activity activity, ChildControllersRegistry childRegistry, String id, Presenter presenter, Options initialOptions) {
super(activity, childRegistry, id, presenter, initialOptions);
}

@Override
public void setWaitForRender(Bool waitForRender) {
super.setWaitForRender(waitForRender);
applyOnController(getCurrentChild(), controller -> ((ViewController) controller).setWaitForRender(waitForRender));
applyOnController(getCurrentChild(), currentChild -> currentChild.setWaitForRender(waitForRender));
}

@Override
public void setDefaultOptions(Options defaultOptions) {
super.setDefaultOptions(defaultOptions);
forEach(getChildControllers(), (child) -> child.setDefaultOptions(defaultOptions));
forEach(getChildControllers(), child -> child.setDefaultOptions(defaultOptions));
}

@Override
Expand Down Expand Up @@ -69,12 +69,6 @@ public boolean isCurrentChild(ViewController child) {

protected abstract ViewController getCurrentChild();

@NonNull
@Override
public T getView() {
return (T) super.getView();
}

@NonNull
@Override
protected abstract T createView();
Expand Down Expand Up @@ -127,8 +121,7 @@ public void applyChildOptions(Options options, ViewController child) {
}

@CallSuper
public void mergeChildOptions(Options options, ViewController childController) {

public void mergeChildOptions(Options options, ViewController child) {
}

@Override
Expand All @@ -140,7 +133,7 @@ public void destroy() {
@SuppressWarnings("WeakerAccess")
@CallSuper
protected void clearOptions() {
performOnParentController(parent -> ((ParentController) parent).clearOptions());
performOnParentController(ParentController::clearOptions);
options = initialOptions.copy().clearOneTimeOptions();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public abstract class ViewController<T extends ViewGroup> implements ViewTreeObserver.OnGlobalLayoutListener,
ViewGroup.OnHierarchyChangeListener,
BehaviourAdapter<T> {
BehaviourAdapter {

private final List<Runnable> onAppearedListeners = new ArrayList();
private boolean appearEventPosted;
Expand Down Expand Up @@ -146,7 +146,7 @@ public void performOnView(Func1<View> task) {
if (view != null) task.run(view);
}

protected void performOnParentController(Func1<ParentController> task) {
public void performOnParentController(Func1<ParentController> task) {
if (parentController != null) task.run(parentController);
}

Expand Down Expand Up @@ -326,13 +326,13 @@ public List<Element> getElements() {

@Override
@CallSuper
public boolean onMeasureChild(CoordinatorLayout parent, T child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
public boolean onMeasureChild(CoordinatorLayout parent, ViewGroup child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
perform(findController(child), ViewController::applyTopInset);
return false;
}

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, T child, View dependency) {
public boolean onDependentViewChanged(CoordinatorLayout parent, ViewGroup child, View dependency) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ public void mergeOptions(Options options) {
public void applyChildOptions(Options options, ViewController child) {
super.applyChildOptions(options, child);
presenter.applyChildOptions(resolveCurrentOptions(), child);
performOnParentController(parentController ->
((ParentController) parentController).applyChildOptions(
this.options.copy()
.clearBottomTabsOptions()
.clearBottomTabOptions(),
performOnParentController(parent -> parent.applyChildOptions(
this.options.copy()
.clearBottomTabsOptions()
.clearBottomTabOptions(),
child
)
);
Expand All @@ -124,9 +123,7 @@ public void mergeChildOptions(Options options, ViewController child) {
super.mergeChildOptions(options, child);
presenter.mergeChildOptions(options, child);
tabPresenter.mergeChildOptions(options, child);
performOnParentController(parentController ->
((ParentController) parentController).mergeChildOptions(options.copy().clearBottomTabsOptions(), child)
);
performOnParentController(parent -> parent.mergeChildOptions(options.copy().clearBottomTabsOptions(), child));
}

@Override
Expand Down Expand Up @@ -165,7 +162,7 @@ private List<AHBottomNavigationItem> createTabs() {
});
}

public int getSelectedIndex() {
int getSelectedIndex() {
return bottomTabs.getCurrentItem();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ public void applyOptions(Options options) {
public void applyChildOptions(Options options, ViewController child) {
super.applyChildOptions(options, child);
presenter.applyChildOptions(resolveCurrentOptions());
performOnParentController(parentController ->
((ParentController) parentController).applyChildOptions(this.options, child)
);
performOnParentController(parent -> parent.applyChildOptions(this.options, child));
}

@Override
public void mergeChildOptions(Options options, ViewController child) {
super.mergeChildOptions(options, child);
presenter.mergeOptions(options.sideMenuRootOptions);
performOnParentController(parent -> parent.mergeChildOptions(options, child));
}

@Override
Expand All @@ -120,7 +119,7 @@ public Options resolveCurrentOptions() {
return options;
}

public boolean isDrawerOpen(int gravity) {
private boolean isDrawerOpen(int gravity) {
return !isDestroyed() && getView().isDrawerOpen(gravity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public void applyChildOptions(Options options, ViewController child) {
if (child.getView() instanceof ReactComponent) {
fabOptionsPresenter.applyOptions(this.options.fabOptions, (ReactComponent) child.getView(), getView());
}
performOnParentController(parentController ->
((ParentController) parentController).applyChildOptions(
performOnParentController(parent ->
parent.applyChildOptions(
this.options.copy()
.clearTopBarOptions()
.clearAnimationOptions()
Expand All @@ -123,8 +123,8 @@ public void mergeChildOptions(Options options, ViewController child) {
fabOptionsPresenter.mergeOptions(options.fabOptions, (ReactComponent) child, getView());
}
}
performOnParentController(parentController ->
((ParentController) parentController).mergeChildOptions(
performOnParentController(parent ->
parent.mergeChildOptions(
options.copy()
.clearTopBarOptions()
.clearAnimationOptions()
Expand Down Expand Up @@ -221,13 +221,17 @@ public void onSuccess(String childId) {
if (toRemove != null && resolvedOptions.animations.setStackRoot.enabled.isTrueOrUndefined()) {
if (resolvedOptions.animations.setStackRoot.waitForRender.isTrue()) {
child.getView().setAlpha(0);
child.addOnAppearedListener(() -> animator.push(child.getView(), resolvedOptions.animations.setStackRoot, resolvedOptions.transitions, toRemove.getElements(), child.getElements(), () -> {
listenerAdapter.onSuccess(child.getId());
}));
child.addOnAppearedListener(() -> animator.push(
child.getView(),
resolvedOptions.animations.setStackRoot,
resolvedOptions.transitions,
toRemove.getElements(),
child.getElements(),
() -> listenerAdapter.onSuccess(child.getId())
)
);
} else {
animator.push(child.getView(), resolvedOptions.animations.setStackRoot, () -> {
listenerAdapter.onSuccess(child.getId());
});
animator.push(child.getView(), resolvedOptions.animations.setStackRoot, () -> listenerAdapter.onSuccess(child.getId()));
}
} else {
listenerAdapter.onSuccess(child.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.reactnativenavigation.views;

import androidx.coordinatorlayout.widget.CoordinatorLayout;
import android.view.View;
import android.view.ViewGroup;

public interface BehaviourAdapter<V extends ViewGroup> {
import androidx.coordinatorlayout.widget.CoordinatorLayout;

public interface BehaviourAdapter {
/**
* @see CoordinatorLayout.Behavior#onMeasureChild
* @return true if the Behavior measured the child view, false if the CoordinatorLayout should perform its default measurement
*/
boolean onMeasureChild(CoordinatorLayout parent, V child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed);
boolean onMeasureChild(CoordinatorLayout parent, ViewGroup child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed);

/**
* @see CoordinatorLayout.Behavior#onDependentViewChanged
* @return true if the Behavior changed the child view's size or position, false otherwise
*/
boolean onDependentViewChanged(CoordinatorLayout parent, V child, View dependency);
boolean onDependentViewChanged(CoordinatorLayout parent, ViewGroup child, View dependency);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package com.reactnativenavigation.views;

import androidx.coordinatorlayout.widget.CoordinatorLayout;
import android.view.View;
import android.view.ViewGroup;

public class BehaviourDelegate<V extends ViewGroup> extends CoordinatorLayout.Behavior<V> {
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

public class BehaviourDelegate extends CoordinatorLayout.Behavior<ViewGroup> {

private BehaviourAdapter delegate;

public BehaviourDelegate(BehaviourAdapter<V> delegate) {
public BehaviourDelegate(BehaviourAdapter delegate) {
this.delegate = delegate;
}

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, V child, View dependency) {
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull ViewGroup child, @NonNull View dependency) {
return delegate.onDependentViewChanged(parent, child, dependency);
}

@Override
public boolean onMeasureChild(CoordinatorLayout parent, V child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
public boolean onMeasureChild(@NonNull CoordinatorLayout parent, @NonNull ViewGroup child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
return delegate.onMeasureChild(parent, child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.reactnativenavigation.views.bottomtabs;

import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import android.view.View;
import android.view.ViewGroup;

import com.reactnativenavigation.views.BehaviourAdapter;
import com.reactnativenavigation.views.BehaviourDelegate;
import com.reactnativenavigation.views.BottomTabs;

public class BottomTabsBehaviour<V extends ViewGroup> extends BehaviourDelegate<V> {
public BottomTabsBehaviour(BehaviourAdapter<V> delegate) {
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

public class BottomTabsBehaviour extends BehaviourDelegate {
public BottomTabsBehaviour(BehaviourAdapter delegate) {
super(delegate);
}

@Override
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull V child, @NonNull View dependency) {
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull ViewGroup child, @NonNull View dependency) {
return dependency instanceof BottomTabs;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.reactnativenavigation.views.stack;

import androidx.coordinatorlayout.widget.CoordinatorLayout;
import android.view.View;
import android.view.ViewGroup;

import com.reactnativenavigation.views.BehaviourAdapter;
import com.reactnativenavigation.views.BehaviourDelegate;
import com.reactnativenavigation.views.topbar.TopBar;

public class StackBehaviour<V extends ViewGroup> extends BehaviourDelegate<V> {
public StackBehaviour(BehaviourAdapter<V> delegate) {
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

public class StackBehaviour<V extends ViewGroup> extends BehaviourDelegate {
public StackBehaviour(BehaviourAdapter delegate) {
super(delegate);
}

@Override
public boolean layoutDependsOn(CoordinatorLayout parent, V child, View dependency) {
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull ViewGroup child, @NonNull View dependency) {
return dependency instanceof TopBar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public void mergeChildOptions() {
Options options = new Options();
uut.mergeChildOptions(options, child);
verify(presenter).mergeOptions(options.sideMenuRootOptions);
verify(parent).mergeChildOptions(options, child);
}

@Test
Expand Down