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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public NavigationModule(ReactApplicationContext reactContext, ReactInstanceManag
this.jsonParser = jsonParser;
this.layoutFactory = layoutFactory;
reactContext.addLifecycleEventListener(new LifecycleEventListenerAdapter() {
@Override
public void onHostPause() {
super.onHostPause();
navigator().onHostPause();
}

@Override
public void onHostResume() {
eventEmitter = new EventEmitter(reactContext);
Expand All @@ -63,6 +69,7 @@ public void onHostResume() {
navigator().getChildRegistry(),
((NavigationApplication) activity().getApplication()).getExternalComponents()
);
navigator().onHostResume();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,11 @@ CoordinatorLayout getModalsLayout() {
CoordinatorLayout getOverlaysLayout() {
return overlaysLayout;
}

public void onHostPause() {
super.onViewDisappear();
}
public void onHostResume(){
super.onViewDidAppear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ public void setDefaultOptions(Options defaultOptions) {

@Override
public void onViewDidAppear() {
getCurrentChild().onViewDidAppear();
super.onViewDidAppear();
ViewController currentChild = getCurrentChild();
if (currentChild != null) currentChild.onViewDidAppear();
}

@Override
public void onViewDisappear() {
super.onViewDisappear();
ViewController currentChild = getCurrentChild();
if (currentChild != null) currentChild.onViewDisappear();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ public void bindViews() {
verify(modalStack).setModalsLayout(uut.getModalsLayout());
}

@Test
public void shouldCallOnViewDidAppearWhenHostResumes() {
SimpleViewController child1 = spy(this.child1);
uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
uut.onHostResume();
verify(child1,times(2)).onViewDidAppear();
}

@Test
public void shouldCallOnViewDisappearWhenHostPauses() {
SimpleViewController child1 = spy(this.child1);
uut.setRoot(child1, new CommandListenerAdapter(), reactInstanceManager);
uut.onHostPause();
verify(child1).onViewDidAppear();
}

@Test
public void setDefaultOptions() {
uut.setDefaultOptions(new Options());
Expand All @@ -160,12 +176,11 @@ public void setRoot_delegatesToRootPresenter() {
CommandListenerAdapter listener = new CommandListenerAdapter();
uut.setRoot(child1, listener, reactInstanceManager);
ArgumentCaptor<CommandListenerAdapter> captor = ArgumentCaptor.forClass(CommandListenerAdapter.class);
verify(rootPresenter).setRoot(eq(child1), eq(null),eq(uut.getDefaultOptions()), captor.capture(), eq(reactInstanceManager));
verify(rootPresenter).setRoot(eq(child1), eq(null), eq(uut.getDefaultOptions()), captor.capture(), eq(reactInstanceManager));
assertThat(captor.getValue().getListener()).isEqualTo(listener);
}



@Test
public void setRoot_clearsSplashLayout() {
FrameLayout content = activity.findViewById(android.R.id.content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -83,6 +84,31 @@ public Collection<ViewController> getChildControllers() {
});
}

@Test
public void onViewDidAppearShouldCallCurrentChildDidAppear(){
SimpleViewController child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
SimpleViewController child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
children.add(child1);
children.add(child2);

uut.onViewDidAppear();

verify(child1).onViewDidAppear();
verify(child2,never()).onViewDidAppear();
}

@Test
public void onViewDisappearShouldCallCurrentChildDisAppear(){
SimpleViewController child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
SimpleViewController child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
children.add(child1);
children.add(child2);

uut.onViewDisappear();

verify(child1).onViewDisappear();
verify(child2,never()).onViewDisappear();
}
@Test
public void holdsViewGroup() {
assertThat(uut.getView()).isInstanceOf(ViewGroup.class);
Expand Down