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

Unwrap Context in order to retrieve Activity subclass #59

Merged
merged 1 commit into from
Jan 15, 2019
Merged
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 @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
Expand Down Expand Up @@ -93,8 +94,12 @@ private FragmentActivity findRootFragmentActivity() {
if (!(parent instanceof ReactRootView)) {
throw new IllegalStateException("ScreenContainer is not attached under ReactRootView");
}
// ReactRootView is expected to be initialized with the main React Activity as a context
// ReactRootView is expected to be initialized with the main React Activity as a context but
// in case of Expo the activity is wrapped in ContextWrapper and we need to unwrap it
Context context = ((ReactRootView) parent).getContext();
while (!(context instanceof FragmentActivity) && context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
}
if (!(context instanceof FragmentActivity)) {
throw new IllegalStateException(
"In order to use RNScreens components your app's activity need to extend ReactFragmentActivity or ReactCompatActivity");
Expand Down