-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Migrating libraries dependent on the activity in RN 0.29 #8509
Comments
49f20f4 |
@nihgwu That would be really helpful! I wanted to update to 0.29 but wasn't sure how to handle react-native-fbsdk which requires implementing |
@ryankask well, the following is the working version for RN0.29 modified from react-native-splashscreen package com.liteneo.reader;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactMethod;
public class SplashScreenModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
private static Dialog splashDialog;
private ImageView splashImageView;
private boolean splashed = false;
private Activity activity;
public SplashScreenModule(ReactApplicationContext reactContext) {
super(reactContext);
reactContext.addLifecycleEventListener(this);
}
@Override
public String getName() {
return "SplashScreen";
}
@Override
public void onHostResume() {
if(splashed) return;
splashed = true;
show();
}
@Override
public void onHostPause() {
}
@Override
public void onHostDestroy() {
}
@ReactMethod
public void hide() {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
removeSplashScreen();
}
}, 500);
}
private void removeSplashScreen() {
Activity currentActivity = getCurrentActivity();
currentActivity.runOnUiThread(new Runnable() {
public void run() {
if (splashDialog != null && splashDialog.isShowing()) {
AlphaAnimation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setDuration(1000);
View view = ((ViewGroup)splashDialog.getWindow().getDecorView()).getChildAt(0);
view.startAnimation(fadeOut);
fadeOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
splashDialog.dismiss();
splashDialog = null;
splashImageView = null;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
});
}
private int getSplashId() {
Activity currentActivity = getCurrentActivity();
int drawableId = currentActivity.getResources().getIdentifier("screen", "drawable", currentActivity.getClass().getPackage().getName());
if (drawableId == 0) {
drawableId = currentActivity.getResources().getIdentifier("screen", "drawable", currentActivity.getPackageName());
}
return drawableId;
}
@ReactMethod
public void show() {
final int drawableId = getSplashId();
if ((splashDialog != null && splashDialog.isShowing())||(drawableId == 0)) {
return;
}
final Activity currentActivity = getCurrentActivity();
currentActivity.runOnUiThread(new Runnable() {
public void run() {
// Get reference to display
Display display = currentActivity.getWindowManager().getDefaultDisplay();
Context context = currentActivity;
// Use an ImageView to render the image because of its flexible scaling options.
splashImageView = new ImageView(context);
splashImageView.setImageResource(drawableId);
LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
splashImageView.setLayoutParams(layoutParams);
splashImageView.setMinimumHeight(display.getHeight());
splashImageView.setMinimumWidth(display.getWidth());
splashImageView.setBackgroundColor(Color.BLACK);
splashImageView.setScaleType(ImageView.ScaleType.FIT_XY);
// Create and show the dialog
splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
// check to see if the splash screen should be full screen
if ((currentActivity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
splashDialog.setContentView(splashImageView);
splashDialog.setCancelable(false);
splashDialog.show();
}
});
}
} |
I'm going to close this as we've outlined the solutions in 49f20f4. The libraries need to be updated to use |
Reviewed By: astreet Differential Revision: D3328342 fbshipit-source-id: af4e825d0b7c2d3d4490094a939e97cc527dd242
Hi,
Using RN 0.29 rc, I noticed that packages requiring activity as a parameter cannot be passed on MainApplication.java.
For example:
The package remobile/react-native-splash-screen
(this)
gets a red line in Android Studio.Did anyone found an appropriate solution?
The text was updated successfully, but these errors were encountered: