react-native-navigation的迁移库

SplashActivity.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.reactnativenavigation.controllers;
  2. import android.graphics.Color;
  3. import android.os.Bundle;
  4. import android.support.annotation.LayoutRes;
  5. import android.support.annotation.Nullable;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.view.View;
  8. import com.reactnativenavigation.NavigationApplication;
  9. import com.reactnativenavigation.react.ReactDevPermission;
  10. public abstract class SplashActivity extends AppCompatActivity {
  11. @Override
  12. protected void onCreate(@Nullable Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setSplashLayout();
  15. IntentDataHandler.saveIntentData(getIntent());
  16. }
  17. @Override
  18. protected void onResume() {
  19. super.onResume();
  20. if (NavigationApplication.instance.getReactGateway().hasStartedCreatingContext()) {
  21. finish();
  22. }
  23. if (ReactDevPermission.shouldAskPermission()) {
  24. ReactDevPermission.askPermission(this);
  25. return;
  26. }
  27. if (NavigationApplication.instance.isReactContextInitialized()) {
  28. finish();
  29. return;
  30. }
  31. // TODO I'm starting to think this entire flow is incorrect and should be done in Application
  32. NavigationApplication.instance.startReactContextOnceInBackgroundAndExecuteJS();
  33. }
  34. private void setSplashLayout() {
  35. final int splashLayout = getSplashLayout();
  36. if (splashLayout > 0) {
  37. setContentView(splashLayout);
  38. } else {
  39. setContentView(createSplashLayout());
  40. }
  41. }
  42. /**
  43. * @return xml layout res id
  44. */
  45. @LayoutRes
  46. public int getSplashLayout() {
  47. return 0;
  48. }
  49. /**
  50. * @return the layout you would like to show while react's js context loads
  51. */
  52. public View createSplashLayout() {
  53. View view = new View(this);
  54. view.setBackgroundColor(Color.WHITE);
  55. return view;
  56. }
  57. }