Skip to content

Commit 80bef04

Browse files
authored
Merge pull request #190 from deepueg/fix-onfocus-rn64
Fix onfocus rn64
2 parents 0037a80 + 9c9d836 commit 80bef04

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

android/lib/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ android {
2727
testOptions {
2828
unitTests.returnDefaultValues = true
2929
}
30+
compileOptions {
31+
sourceCompatibility = '1.8'
32+
targetCompatibility = '1.8'
33+
}
3034
}
3135

3236
dependencies {

android/lib/src/androidTest/java/com/ern/api/impl/LaunchConfigTests.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import androidx.annotation.NonNull;
66
import androidx.annotation.Nullable;
7+
import androidx.lifecycle.Lifecycle;
78
import androidx.test.core.app.ActivityScenario;
89
import androidx.test.espresso.NoMatchingViewException;
910
import androidx.test.espresso.ViewAssertion;
@@ -269,12 +270,19 @@ public void check(View view, NoMatchingViewException noViewFoundException) {
269270
}
270271
});
271272
onView(withContentDescription(R.string.abc_action_bar_up_description)).perform(click());
272-
scenario.onActivity(new ActivityScenario.ActivityAction<UpEnabledForRootActivity>() {
273-
@Override
274-
public void perform(UpEnabledForRootActivity activity) {
275-
assertThat(activity.isFinishing()).isTrue();
276-
}
277-
});
273+
Lifecycle.State state = scenario.getState();
274+
// Sometimes the activity gets destroyed immediately ot it can be delayed.
275+
// Covering both cases below.
276+
if(state == Lifecycle.State.STARTED) {
277+
scenario.onActivity(new ActivityScenario.ActivityAction<UpEnabledForRootActivity>() {
278+
@Override
279+
public void perform(UpEnabledForRootActivity activity) {
280+
assertThat(activity.isFinishing()).isTrue();
281+
}
282+
});
283+
} else {
284+
assertThat(scenario.getState()).isEqualTo(Lifecycle.State.DESTROYED);
285+
}
278286
}
279287

280288
@Test

android/lib/src/androidTest/java/com/ern/api/impl/NavigationFragmentDelegateTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.view.Menu;
88
import android.view.MenuInflater;
99
import android.view.View;
10+
import android.widget.LinearLayout;
1011

1112
import androidx.annotation.NonNull;
1213
import androidx.annotation.Nullable;
@@ -84,7 +85,7 @@ public void perform(TestActivity activity) {
8485
assertThat(fragment).isInstanceOf(LayoutConfiguredFragment.class);
8586
LayoutConfiguredFragment testFragment = (LayoutConfiguredFragment) fragment;
8687
assertThat(testFragment.getView()).isNotNull();
87-
assertThat(testFragment.getView().findViewById(com.walmartlabs.ern.navigation.test.R.id.miniapp_view_container)).isNotNull();
88+
assertThat((LinearLayout) testFragment.getView().findViewById(com.walmartlabs.ern.navigation.test.R.id.miniapp_view_container)).isNotNull();
8889
}
8990
});
9091
}

android/lib/src/main/java/com/ern/api/impl/navigation/ElectrodeNavigationFragmentDelegate.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.graphics.drawable.Drawable;
44
import android.os.Bundle;
5+
import android.os.Handler;
6+
import android.os.Looper;
57
import android.text.TextUtils;
68
import android.view.Menu;
79
import android.view.MenuInflater;
@@ -59,6 +61,8 @@ public class ElectrodeNavigationFragmentDelegate<T extends ElectrodeBaseFragment
5961

6062
protected boolean ignoreRnNavBarUpdate;
6163

64+
private Handler mMainHandler = new Handler(Looper.getMainLooper());
65+
6266
private final Observer<Route> routeObserver = new Observer<Route>() {
6367
@Override
6468
public void onChanged(@Nullable Route route) {
@@ -170,7 +174,7 @@ public void onResume() {
170174
if (mNavViewModel != null) {
171175
mNavViewModel.registerNavRequestHandler();
172176
}
173-
EnNavigationApi.events().emitNavEvent(new NavEventData.Builder(NavEventType.DID_FOCUS.toString()).viewId(getMiniAppViewIdentifier()).build());
177+
mMainHandler.post(() -> EnNavigationApi.events().emitNavEvent(new NavEventData.Builder(NavEventType.DID_FOCUS.toString()).viewId(getMiniAppViewIdentifier()).build()));
174178
}
175179

176180
@SuppressWarnings("unused")
@@ -204,7 +208,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
204208
@CallSuper
205209
public void onPause() {
206210
super.onPause();
207-
EnNavigationApi.events().emitNavEvent(new NavEventData.Builder(NavEventType.DID_BLUR.toString()).viewId(getMiniAppViewIdentifier()).build());
211+
mMainHandler.post(() -> EnNavigationApi.events().emitNavEvent(new NavEventData.Builder(NavEventType.DID_BLUR.toString()).viewId(getMiniAppViewIdentifier()).build()));
208212
}
209213

210214
@Override

0 commit comments

Comments
 (0)