Java Code Examples for com.facebook.react.bridge.CatalystInstance

The following are top voted examples for showing how to use com.facebook.react.bridge.CatalystInstance. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: react-native-android-activity   File: ActivityStarterModule.java   View source code 6 votes vote down vote up
@ReactMethod
void callJavaScript() {
    Activity activity = getCurrentActivity();
    if (activity != null) {
        MainApplication application = (MainApplication) activity.getApplication();
        ReactNativeHost reactNativeHost = application.getReactNativeHost();
        ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
        ReactContext reactContext = reactInstanceManager.getCurrentReactContext();

        if (reactContext != null) {
            CatalystInstance catalystInstance = reactContext.getCatalystInstance();
            WritableNativeArray params = new WritableNativeArray();
            params.pushString("Hello, JavaScript!");
            catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params);
        }
    }
}
 
Example 2
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachMeasuredRootViewToInstance");
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  rootView.setRootViewTag(rootTag);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = Arguments.makeNativeMap(launchOptions);
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
  rootView.onAttachedToReactInstance();
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 3
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 6 votes vote down vote up
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachMeasuredRootViewToInstance");
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  rootView.setRootViewTag(rootTag);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = Arguments.makeNativeMap(launchOptions);
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
  rootView.onAttachedToReactInstance();
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 4
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void setupReactContext(ReactApplicationContext reactContext) {
  UiThreadUtil.assertOnUiThread();
  Assertions.assertCondition(mCurrentReactContext == null);
  mCurrentReactContext = Assertions.assertNotNull(reactContext);
  CatalystInstance catalystInstance =
      Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  for (ReactRootView rootView : mAttachedRootViews) {
    attachMeasuredRootViewToInstance(rootView, catalystInstance);
  }

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  listeners = mReactInstanceEventListeners.toArray(listeners);

  for (ReactInstanceEventListener listener : listeners) {
    listener.onReactContextInitialized(reactContext);
  }
}
 
Example 5
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = launchOptions != null
      ? Arguments.fromBundle(launchOptions)
      : Arguments.createMap();
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
}
 
Example 6
Project: ReactNativeSignatureExample   File: ReactTestHelper.java   View source code 6 votes vote down vote up
@Override
public CatalystInstance build() {
  return new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(new JSCJavaScriptExecutor(new WritableNativeMap()))
    .setRegistry(mNativeModuleRegistryBuilder.build())
    .setJSModulesConfig(mJSModulesConfigBuilder.build())
    .setJSBundleLoader(JSBundleLoader.createFileLoader(
                         mContext,
                         "assets://AndroidTestBundle.js"))
    .setNativeModuleCallExceptionHandler(
      new NativeModuleCallExceptionHandler() {
          @Override
          public void handleException(Exception e) {
            throw new RuntimeException(e);
          }
      })
    .build();
}
 
Example 7
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void setupReactContext(ReactApplicationContext reactContext) {
  UiThreadUtil.assertOnUiThread();
  Assertions.assertCondition(mCurrentReactContext == null);
  mCurrentReactContext = Assertions.assertNotNull(reactContext);
  CatalystInstance catalystInstance =
      Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  for (ReactRootView rootView : mAttachedRootViews) {
    attachMeasuredRootViewToInstance(rootView, catalystInstance);
  }

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  listeners = mReactInstanceEventListeners.toArray(listeners);

  for (ReactInstanceEventListener listener : listeners) {
    listener.onReactContextInitialized(reactContext);
  }
}
 
Example 8
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = launchOptions != null
      ? Arguments.fromBundle(launchOptions)
      : Arguments.createMap();
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
}
 
Example 9
Project: react-native-ibeacon-android   File: ReactTestHelper.java   View source code 6 votes vote down vote up
@Override
public CatalystInstance build() {
  return new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(new JSCJavaScriptExecutor(new WritableNativeMap()))
    .setRegistry(mNativeModuleRegistryBuilder.build())
    .setJSModulesConfig(mJSModulesConfigBuilder.build())
    .setJSBundleLoader(JSBundleLoader.createFileLoader(
                         mContext,
                         "assets://AndroidTestBundle.js"))
    .setNativeModuleCallExceptionHandler(
      new NativeModuleCallExceptionHandler() {
          @Override
          public void handleException(Exception e) {
            throw new RuntimeException(e);
          }
      })
    .build();
}
 
Example 10
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void setupReactContext(ReactApplicationContext reactContext) {
  UiThreadUtil.assertOnUiThread();
  Assertions.assertCondition(mCurrentReactContext == null);
  mCurrentReactContext = Assertions.assertNotNull(reactContext);
  CatalystInstance catalystInstance =
      Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  for (ReactRootView rootView : mAttachedRootViews) {
    attachMeasuredRootViewToInstance(rootView, catalystInstance);
  }

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  listeners = mReactInstanceEventListeners.toArray(listeners);

  for (ReactInstanceEventListener listener : listeners) {
    listener.onReactContextInitialized(reactContext);
  }
}
 
Example 11
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = launchOptions != null
      ? Arguments.fromBundle(launchOptions)
      : Arguments.createMap();
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
}
 
Example 12
Project: react-native-box-loaders   File: ReactTestHelper.java   View source code 6 votes vote down vote up
@Override
public CatalystInstance build() {
  return new CatalystInstanceImpl.Builder()
    .setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
    .setJSExecutor(new JSCJavaScriptExecutor(new WritableNativeMap()))
    .setRegistry(mNativeModuleRegistryBuilder.build())
    .setJSModulesConfig(mJSModulesConfigBuilder.build())
    .setJSBundleLoader(JSBundleLoader.createFileLoader(
                         mContext,
                         "assets://AndroidTestBundle.js"))
    .setNativeModuleCallExceptionHandler(
      new NativeModuleCallExceptionHandler() {
          @Override
          public void handleException(Exception e) {
            throw new RuntimeException(e);
          }
      })
    .build();
}
 
Example 13
Project: Ironman   File: XReactInstanceManagerImpl.java   View source code 6 votes vote down vote up
private void attachMeasuredRootViewToInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachMeasuredRootViewToInstance");
  UiThreadUtil.assertOnUiThread();

  // Reset view content as it's going to be populated by the application content from JS
  rootView.removeAllViews();
  rootView.setId(View.NO_ID);

  UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
  int rootTag = uiManagerModule.addMeasuredRootView(rootView);
  rootView.setRootViewTag(rootTag);
  @Nullable Bundle launchOptions = rootView.getLaunchOptions();
  WritableMap initialProps = Arguments.makeNativeMap(launchOptions);
  String jsAppModuleName = rootView.getJSModuleName();

  WritableNativeMap appParams = new WritableNativeMap();
  appParams.putDouble("rootTag", rootTag);
  appParams.putMap("initialProps", initialProps);
  catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
 
Example 14
Project: react-native-android-audio-demo   File: AudioService.java   View source code 6 votes vote down vote up
@Override
public void onCreate() {
    ReactInstanceManager reactInstanceManager =
            ReactInstanceSingleton.getReactInstanceManager(getApplication());

    ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
    if (reactContext != null) {
        CatalystInstance catalystInstance = reactContext.getCatalystInstance();
        serviceTopLevel = catalystInstance.getJSModule(ServiceTopLevel.class);
        mRemoteViewsModule = catalystInstance.getJSModule(RemoteViewsModule.class);
    } else {
        Log.e(TAG, "Couldn't grab JS service code");
    }

    serviceTopLevel.initService(0);
}
 
Example 15
Project: RNLearn_Project1   File: ModuleDataCleaner.java   View source code 5 votes vote down vote up
public static void cleanDataFromModules(CatalystInstance catalystInstance) {
  for (NativeModule nativeModule : catalystInstance.getNativeModules()) {
    if (nativeModule instanceof Cleanable) {
      FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName());
      ((Cleanable) nativeModule).clearSensitiveData();
    }
  }
}
 
Example 16
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 5 votes vote down vote up
private void setupReactContext(ReactApplicationContext reactContext) {
  ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_END);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "setupReactContext");
  UiThreadUtil.assertOnUiThread();
  Assertions.assertCondition(mCurrentReactContext == null);
  mCurrentReactContext = Assertions.assertNotNull(reactContext);
  CatalystInstance catalystInstance =
      Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  for (ReactRootView rootView : mAttachedRootViews) {
    attachMeasuredRootViewToInstance(rootView, catalystInstance);
  }

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  listeners = mReactInstanceEventListeners.toArray(listeners);

  for (ReactInstanceEventListener listener : listeners) {
    listener.onReactContextInitialized(reactContext);
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
}
 
Example 17
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 5 votes vote down vote up
private void detachViewFromInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();
  catalystInstance.getJSModule(AppRegistry.class)
      .unmountApplicationComponentAtRootTag(rootView.getId());
}
 
Example 18
Project: RNLearn_Project1   File: ReactSliderPropertyTest.java   View source code 5 votes vote down vote up
@Before
public void setup() {
  ReactApplicationContext mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  CatalystInstance mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemedContext = new ThemedReactContext(mContext, mContext);
  mManager = new ReactSliderManager();
}
 
Example 19
Project: RNLearn_Project1   File: ModuleDataCleaner.java   View source code 5 votes vote down vote up
public static void cleanDataFromModules(CatalystInstance catalystInstance) {
  for (NativeModule nativeModule : catalystInstance.getNativeModules()) {
    if (nativeModule instanceof Cleanable) {
      FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName());
      ((Cleanable) nativeModule).clearSensitiveData();
    }
  }
}
 
Example 20
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 5 votes vote down vote up
private void setupReactContext(ReactApplicationContext reactContext) {
  ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_END);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "setupReactContext");
  UiThreadUtil.assertOnUiThread();
  Assertions.assertCondition(mCurrentReactContext == null);
  mCurrentReactContext = Assertions.assertNotNull(reactContext);
  CatalystInstance catalystInstance =
      Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  for (ReactRootView rootView : mAttachedRootViews) {
    attachMeasuredRootViewToInstance(rootView, catalystInstance);
  }

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  listeners = mReactInstanceEventListeners.toArray(listeners);

  for (ReactInstanceEventListener listener : listeners) {
    listener.onReactContextInitialized(reactContext);
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
}
 
Example 21
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 5 votes vote down vote up
private void detachViewFromInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();
  catalystInstance.getJSModule(AppRegistry.class)
      .unmountApplicationComponentAtRootTag(rootView.getId());
}
 
Example 22
Project: RNLearn_Project1   File: ReactSliderPropertyTest.java   View source code 5 votes vote down vote up
@Before
public void setup() {
  ReactApplicationContext mContext = new ReactApplicationContext(RuntimeEnvironment.application);
  CatalystInstance mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
  mContext.initializeWithInstance(mCatalystInstanceMock);
  mThemedContext = new ThemedReactContext(mContext, mContext);
  mManager = new ReactSliderManager();
}
 
Example 23
Project: ReactNativeSignatureExample   File: ModuleDataCleaner.java   View source code 5 votes vote down vote up
public static void cleanDataFromModules(CatalystInstance catalystInstance) {
  for (NativeModule nativeModule : catalystInstance.getNativeModules()) {
    if (nativeModule instanceof Cleanable) {
      FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName());
      ((Cleanable) nativeModule).clearSensitiveData();
    }
  }
}
 
Example 24
Project: ReactNativeSignatureExample   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void detachViewFromInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();
  catalystInstance.getJSModule(AppRegistry.class)
      .unmountApplicationComponentAtRootTag(rootView.getId());
}
 
Example 25
Project: ReactNativeSignatureExample   File: ReactTestHelper.java   View source code 5 votes vote down vote up
public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder(
    final ReactIntegrationTestCase testCase) {
  final ReactTestFactory.ReactInstanceEasyBuilder builder =
    getReactTestFactory().getCatalystInstanceBuilder();
  ReactTestFactory.ReactInstanceEasyBuilder postBuilder =
    new ReactTestFactory.ReactInstanceEasyBuilder() {
      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder setContext(Context context) {
        builder.setContext(context);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addNativeModule(NativeModule module) {
        builder.addNativeModule(module);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass) {
        builder.addJSModule(moduleInterfaceClass);
        return this;
      }

      @Override
      public CatalystInstance build() {
        CatalystInstance instance = builder.build();
        testCase.initializeWithInstance(instance);
        instance.runJSBundle();
        testCase.waitForBridgeAndUIIdle();
        return instance;
      }
    };

  postBuilder.setContext(testCase.getContext());
  return postBuilder;
}
 
Example 26
Project: ReactNativeSignatureExample   File: TimingModuleTest.java   View source code 5 votes vote down vote up
@Before
public void prepareModules() {
  PowerMockito.mockStatic(Arguments.class);
  when(Arguments.createArray()).thenAnswer(
      new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          return new JavaOnlyArray();
        }
      });

  PowerMockito.mockStatic(SystemClock.class);
  when(SystemClock.currentTimeMillis()).thenReturn(mCurrentTimeNs / 1000000);
  when(SystemClock.nanoTime()).thenReturn(mCurrentTimeNs);

  mChoreographerMock = mock(ReactChoreographer.class);
  PowerMockito.mockStatic(ReactChoreographer.class);
  when(ReactChoreographer.getInstance()).thenReturn(mChoreographerMock);

  CatalystInstance reactInstance = mock(CatalystInstance.class);
  ReactApplicationContext reactContext = mock(ReactApplicationContext.class);
  when(reactContext.getCatalystInstance()).thenReturn(reactInstance);

  mCurrentTimeNs = 0;
  mPostFrameCallbackHandler = new PostFrameCallbackHandler();

  doAnswer(mPostFrameCallbackHandler)
      .when(mChoreographerMock)
      .postFrameCallback(
          eq(ReactChoreographer.CallbackType.TIMERS_EVENTS),
          any(Choreographer.FrameCallback.class));

  mTiming = new Timing(reactContext);
  mJSTimersMock = mock(JSTimersExecution.class);
  mExecutorTokenMock = mock(ExecutorToken.class);
  when(reactContext.getJSModule(mExecutorTokenMock, JSTimersExecution.class)).thenReturn(mJSTimersMock);
  mTiming.initialize();
}
 
Example 27
Project: react-native-ibeacon-android   File: ModuleDataCleaner.java   View source code 5 votes vote down vote up
public static void cleanDataFromModules(CatalystInstance catalystInstance) {
  for (NativeModule nativeModule : catalystInstance.getNativeModules()) {
    if (nativeModule instanceof Cleanable) {
      FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName());
      ((Cleanable) nativeModule).clearSensitiveData();
    }
  }
}
 
Example 28
Project: react-native-ibeacon-android   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void detachViewFromInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();
  catalystInstance.getJSModule(AppRegistry.class)
      .unmountApplicationComponentAtRootTag(rootView.getId());
}
 
Example 29
Project: react-native-ibeacon-android   File: ReactTestHelper.java   View source code 5 votes vote down vote up
public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder(
    final ReactIntegrationTestCase testCase) {
  final ReactTestFactory.ReactInstanceEasyBuilder builder =
    getReactTestFactory().getCatalystInstanceBuilder();
  ReactTestFactory.ReactInstanceEasyBuilder postBuilder =
    new ReactTestFactory.ReactInstanceEasyBuilder() {
      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder setContext(Context context) {
        builder.setContext(context);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addNativeModule(NativeModule module) {
        builder.addNativeModule(module);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass) {
        builder.addJSModule(moduleInterfaceClass);
        return this;
      }

      @Override
      public CatalystInstance build() {
        CatalystInstance instance = builder.build();
        testCase.initializeWithInstance(instance);
        instance.runJSBundle();
        testCase.waitForBridgeAndUIIdle();
        return instance;
      }
    };

  postBuilder.setContext(testCase.getContext());
  return postBuilder;
}
 
Example 30
Project: react-native-ibeacon-android   File: TimingModuleTest.java   View source code 5 votes vote down vote up
@Before
public void prepareModules() {
  PowerMockito.mockStatic(Arguments.class);
  when(Arguments.createArray()).thenAnswer(
      new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          return new JavaOnlyArray();
        }
      });

  PowerMockito.mockStatic(SystemClock.class);
  when(SystemClock.currentTimeMillis()).thenReturn(mCurrentTimeNs / 1000000);
  when(SystemClock.nanoTime()).thenReturn(mCurrentTimeNs);

  mChoreographerMock = mock(ReactChoreographer.class);
  PowerMockito.mockStatic(ReactChoreographer.class);
  when(ReactChoreographer.getInstance()).thenReturn(mChoreographerMock);

  CatalystInstance reactInstance = mock(CatalystInstance.class);
  ReactApplicationContext reactContext = mock(ReactApplicationContext.class);
  when(reactContext.getCatalystInstance()).thenReturn(reactInstance);

  mCurrentTimeNs = 0;
  mPostFrameCallbackHandler = new PostFrameCallbackHandler();

  doAnswer(mPostFrameCallbackHandler)
      .when(mChoreographerMock)
      .postFrameCallback(
          eq(ReactChoreographer.CallbackType.TIMERS_EVENTS),
          any(Choreographer.FrameCallback.class));

  mTiming = new Timing(reactContext);
  mJSTimersMock = mock(JSTimersExecution.class);
  mExecutorTokenMock = mock(ExecutorToken.class);
  when(reactContext.getJSModule(mExecutorTokenMock, JSTimersExecution.class)).thenReturn(mJSTimersMock);
  mTiming.initialize();
}
 
Example 31
Project: react-native-box-loaders   File: ModuleDataCleaner.java   View source code 5 votes vote down vote up
public static void cleanDataFromModules(CatalystInstance catalystInstance) {
  for (NativeModule nativeModule : catalystInstance.getNativeModules()) {
    if (nativeModule instanceof Cleanable) {
      FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName());
      ((Cleanable) nativeModule).clearSensitiveData();
    }
  }
}
 
Example 32
Project: react-native-box-loaders   File: ReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void detachViewFromInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();
  catalystInstance.getJSModule(AppRegistry.class)
      .unmountApplicationComponentAtRootTag(rootView.getId());
}
 
Example 33
Project: react-native-box-loaders   File: ReactTestHelper.java   View source code 5 votes vote down vote up
public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder(
    final ReactIntegrationTestCase testCase) {
  final ReactTestFactory.ReactInstanceEasyBuilder builder =
    getReactTestFactory().getCatalystInstanceBuilder();
  ReactTestFactory.ReactInstanceEasyBuilder postBuilder =
    new ReactTestFactory.ReactInstanceEasyBuilder() {
      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder setContext(Context context) {
        builder.setContext(context);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addNativeModule(NativeModule module) {
        builder.addNativeModule(module);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass) {
        builder.addJSModule(moduleInterfaceClass);
        return this;
      }

      @Override
      public CatalystInstance build() {
        CatalystInstance instance = builder.build();
        testCase.initializeWithInstance(instance);
        instance.runJSBundle();
        testCase.waitForBridgeAndUIIdle();
        return instance;
      }
    };

  postBuilder.setContext(testCase.getContext());
  return postBuilder;
}
 
Example 34
Project: react-native-box-loaders   File: TimingModuleTest.java   View source code 5 votes vote down vote up
@Before
public void prepareModules() {
  PowerMockito.mockStatic(Arguments.class);
  when(Arguments.createArray()).thenAnswer(
      new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          return new JavaOnlyArray();
        }
      });

  PowerMockito.mockStatic(SystemClock.class);
  when(SystemClock.currentTimeMillis()).thenReturn(mCurrentTimeNs / 1000000);
  when(SystemClock.nanoTime()).thenReturn(mCurrentTimeNs);

  mChoreographerMock = mock(ReactChoreographer.class);
  PowerMockito.mockStatic(ReactChoreographer.class);
  when(ReactChoreographer.getInstance()).thenReturn(mChoreographerMock);

  CatalystInstance reactInstance = mock(CatalystInstance.class);
  ReactApplicationContext reactContext = mock(ReactApplicationContext.class);
  when(reactContext.getCatalystInstance()).thenReturn(reactInstance);

  mCurrentTimeNs = 0;
  mPostFrameCallbackHandler = new PostFrameCallbackHandler();

  doAnswer(mPostFrameCallbackHandler)
      .when(mChoreographerMock)
      .postFrameCallback(
          eq(ReactChoreographer.CallbackType.TIMERS_EVENTS),
          any(Choreographer.FrameCallback.class));

  mTiming = new Timing(reactContext);
  mJSTimersMock = mock(JSTimersExecution.class);
  mExecutorTokenMock = mock(ExecutorToken.class);
  when(reactContext.getJSModule(mExecutorTokenMock, JSTimersExecution.class)).thenReturn(mJSTimersMock);
  mTiming.initialize();
}
 
Example 35
Project: Ironman   File: ModuleDataCleaner.java   View source code 5 votes vote down vote up
public static void cleanDataFromModules(CatalystInstance catalystInstance) {
  for (NativeModule nativeModule : catalystInstance.getNativeModules()) {
    if (nativeModule instanceof Cleanable) {
      FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName());
      ((Cleanable) nativeModule).clearSensitiveData();
    }
  }
}
 
Example 36
Project: Ironman   File: XReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void setupReactContext(ReactApplicationContext reactContext) {
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_START);
  Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "setupReactContext");
  UiThreadUtil.assertOnUiThread();
  Assertions.assertCondition(mCurrentReactContext == null);
  mCurrentReactContext = Assertions.assertNotNull(reactContext);
  CatalystInstance catalystInstance =
      Assertions.assertNotNull(reactContext.getCatalystInstance());

  catalystInstance.initialize();
  mDevSupportManager.onNewReactContextCreated(reactContext);
  mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
  moveReactContextToCurrentLifecycleState();

  for (ReactRootView rootView : mAttachedRootViews) {
    attachMeasuredRootViewToInstance(rootView, catalystInstance);
  }

  ReactInstanceEventListener[] listeners =
    new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
  listeners = mReactInstanceEventListeners.toArray(listeners);

  for (ReactInstanceEventListener listener : listeners) {
    listener.onReactContextInitialized(reactContext);
  }
  Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
  ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
}
 
Example 37
Project: Ironman   File: XReactInstanceManagerImpl.java   View source code 5 votes vote down vote up
private void detachViewFromInstance(
    ReactRootView rootView,
    CatalystInstance catalystInstance) {
  UiThreadUtil.assertOnUiThread();
  catalystInstance.getJSModule(AppRegistry.class)
      .unmountApplicationComponentAtRootTag(rootView.getId());
}
 
Example 38
Project: RNLearn_Project1   File: ReactTestHelper.java   View source code 4 votes vote down vote up
public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder(
    final ReactIntegrationTestCase testCase) {
  final ReactTestFactory.ReactInstanceEasyBuilder builder =
    getReactTestFactory().getCatalystInstanceBuilder();
  ReactTestFactory.ReactInstanceEasyBuilder postBuilder =
    new ReactTestFactory.ReactInstanceEasyBuilder() {
      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder setContext(Context context) {
        builder.setContext(context);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addNativeModule(NativeModule module) {
        builder.addNativeModule(module);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass) {
        builder.addJSModule(moduleInterfaceClass);
        return this;
      }

      @Override
      public CatalystInstance build() {
        final CatalystInstance instance = builder.build();
        testCase.initializeWithInstance(instance);
        instance.runJSBundle();
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
          @Override
          public void run() {
            instance.initialize();
          }
        });
        testCase.waitForBridgeAndUIIdle();
        return instance;
      }
    };

  postBuilder.setContext(testCase.getContext());
  return postBuilder;
}
 
Example 39
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 4 votes vote down vote up
public void initializeWithInstance(CatalystInstance instance) {
  mInstance = instance;
  mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
  mInstance.addBridgeIdleDebugListener(mBridgeIdleSignaler);
  getContext().initializeWithInstance(mInstance);
}
 
Example 40
Project: RNLearn_Project1   File: ReactTestHelper.java   View source code 4 votes vote down vote up
public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder(
    final ReactIntegrationTestCase testCase) {
  final ReactTestFactory.ReactInstanceEasyBuilder builder =
    getReactTestFactory().getCatalystInstanceBuilder();
  ReactTestFactory.ReactInstanceEasyBuilder postBuilder =
    new ReactTestFactory.ReactInstanceEasyBuilder() {
      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder setContext(Context context) {
        builder.setContext(context);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addNativeModule(NativeModule module) {
        builder.addNativeModule(module);
        return this;
      }

      @Override
      public ReactTestFactory.ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass) {
        builder.addJSModule(moduleInterfaceClass);
        return this;
      }

      @Override
      public CatalystInstance build() {
        final CatalystInstance instance = builder.build();
        testCase.initializeWithInstance(instance);
        instance.runJSBundle();
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
          @Override
          public void run() {
            instance.initialize();
          }
        });
        testCase.waitForBridgeAndUIIdle();
        return instance;
      }
    };

  postBuilder.setContext(testCase.getContext());
  return postBuilder;
}