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

The following are top voted examples for showing how to use com.facebook.react.bridge.ReactContext. 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: RNLearn_Project1   File: ReactIdleDetectionUtil.java   View source code 6 votes vote down vote up
private static void waitForJSIdle(ReactContext reactContext) {
  if (!reactContext.hasActiveCatalystInstance()) {
    return;
  }
  final CountDownLatch latch = new CountDownLatch(1);

  reactContext.runOnJSQueueThread(
      new Runnable() {
        @Override
        public void run() {
          latch.countDown();
        }
      });

  try {
    if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
      throw new RuntimeException("Timed out waiting for JS thread");
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 2
Project: RNLearn_Project1   File: HeadlessJsTaskContext.java   View source code 6 votes vote down vote up
/**
 * Start a JS task. Handles invoking {@link AppRegistry#startHeadlessTask} and notifying
 * listeners.
 *
 * @return a unique id representing this task instance.
 */
public synchronized int startTask(final HeadlessJsTaskConfig taskConfig) {
  UiThreadUtil.assertOnUiThread();
  ReactContext reactContext = Assertions.assertNotNull(
    mReactContext.get(),
    "Tried to start a task on a react context that has already been destroyed");
  if (reactContext.getLifecycleState() == LifecycleState.RESUMED &&
    !taskConfig.isAllowedInForeground()) {
    throw new IllegalStateException(
      "Tried to start task " + taskConfig.getTaskKey() +
        " while in foreground, but this is not allowed.");
  }
  final int taskId = mLastTaskId.incrementAndGet();
  mActiveTasks.add(taskId);
  reactContext.getJSModule(AppRegistry.class)
    .startHeadlessTask(taskId, taskConfig.getTaskKey(), taskConfig.getData());
  if (taskConfig.getTimeout() > 0) {
    scheduleTaskTimeout(taskId, taskConfig.getTimeout());
  }
  for (HeadlessJsTaskEventListener listener : mHeadlessJsTaskEventListeners) {
    listener.onHeadlessJsTaskStart(taskId);
  }
  return taskId;
}
 
Example 3
Project: RNLearn_Project1   File: ReactScrollViewHelper.java   View source code 6 votes vote down vote up
private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scrollEventType) {
  View contentView = scrollView.getChildAt(0);

  if (contentView == null) {
    return;
  }

  ReactContext reactContext = (ReactContext) scrollView.getContext();
  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
      ScrollEvent.obtain(
          scrollView.getId(),
          scrollEventType,
          scrollView.getScrollX(),
          scrollView.getScrollY(),
          contentView.getWidth(),
          contentView.getHeight(),
          scrollView.getWidth(),
          scrollView.getHeight()));
}
 
Example 4
Project: react-native-sockets   File: SocketClient.java   View source code 6 votes vote down vote up
SocketClient(ReadableMap params, ReactContext reactContext) {
    //String addr, int port, boolean autoReconnect
    mReactContext = reactContext;
    dstAddress = params.getString("address");
    dstPort = params.getInt("port");
    if (params.hasKey("reconnect")) {
        reconnectOnClose = params.getBoolean("reconnect");
    }
    if (params.hasKey("maxReconnectAttempts")) {
        maxReconnectAttempts = params.getInt("maxReconnectAttempts");
    }
    if (params.hasKey("reconnectDelay")) {
        reconnectDelay = params.getInt("reconnectDelay");
    }

    Thread socketClientThread = new Thread(new SocketClientThread());
    socketClientThread.start();
}
 
Example 5
Project: RNLearn_Project1   File: ImageEditingManager.java   View source code 6 votes vote down vote up
private CropTask(
    ReactContext context,
    String uri,
    int x,
    int y,
    int width,
    int height,
    Callback success,
    Callback error) {
  super(context);
  if (x < 0 || y < 0 || width <= 0 || height <= 0) {
    throw new JSApplicationIllegalArgumentException(String.format(
        "Invalid crop rectangle: [%d, %d, %d, %d]", x, y, width, height));
  }
  mContext = context;
  mUri = uri;
  mX = x;
  mY = y;
  mWidth = width;
  mHeight = height;
  mSuccess = success;
  mError = error;
}
 
Example 6
Project: react-native-tabbed-view-pager-android   File: TabbedViewPager.java   View source code 6 votes vote down vote up
void setup(ReactContext reactContext) {
  this.setOrientation(VERTICAL);
  this.reactViewPager = new ReactViewPager(reactContext);
  this.reactViewPager.setParentIdCallback(new ReactViewPager.ParentIdCallback() {
    @Override public int getParentId() {
      return getId();
    }
  });
  this.tabLayout = new TabLayout(reactContext);
  this.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
  LayoutParams viewPagerParams =
      new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
          1);

  LayoutParams tabParams =
      new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  this.addView(tabLayout, tabParams);
  this.addView(reactViewPager, viewPagerParams);
  tabLayout.setupWithViewPager(reactViewPager);
}
 
Example 7
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 8
Project: RNLearn_Project1   File: HeadlessJsTaskService.java   View source code 6 votes vote down vote up
@Override
public void onDestroy() {
  super.onDestroy();

  if (getReactNativeHost().hasInstance()) {
    ReactInstanceManager reactInstanceManager = getReactNativeHost().getReactInstanceManager();
    ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
    if (reactContext != null) {
      HeadlessJsTaskContext headlessJsTaskContext =
        HeadlessJsTaskContext.getInstance(reactContext);
      headlessJsTaskContext.removeTaskEventListener(this);
    }
  }
  if (sWakeLock != null) {
    sWakeLock.release();
  }
}
 
Example 9
Project: RNLearn_Project1   File: ReactModalHostView.java   View source code 6 votes vote down vote up
@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
  super.onSizeChanged(w, h, oldw, oldh);
  if (getChildCount() > 0) {
    final int viewTag = getChildAt(0).getId();
    ReactContext reactContext = (ReactContext) getContext();
    reactContext.runOnNativeModulesQueueThread(
      new GuardedRunnable(reactContext) {
        @Override
        public void runGuarded() {
          ((ReactContext) getContext()).getNativeModule(UIManagerModule.class)
            .updateNodeSize(viewTag, w, h);
        }
      });
  }
}
 
Example 10
Project: RNLearn_Project1   File: FrescoModule.java   View source code 6 votes vote down vote up
/**
 * Get the default Fresco configuration builder.
 * Allows adding of configuration options in addition to the default values.
 *
 * @return {@link ImagePipelineConfig.Builder} that has been initialized with default values
 */
public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext context) {
  HashSet<RequestListener> requestListeners = new HashSet<>();
  requestListeners.add(new SystraceRequestListener());

  OkHttpClient client = OkHttpClientProvider.createClient();

  // make sure to forward cookies for any requests via the okHttpClient
  // so that image requests to endpoints that use cookies still work
  CookieJarContainer container = (CookieJarContainer) client.cookieJar();
  ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
  container.setCookieJar(new JavaNetCookieJar(handler));

  return OkHttpImagePipelineConfigFactory
    .newBuilder(context.getApplicationContext(), client)
    .setNetworkFetcher(new ReactOkHttpNetworkFetcher(client))
    .setDownsampleEnabled(false)
    .setRequestListeners(requestListeners);
}
 
Example 11
Project: RNLearn_Project1   File: ReactScrollViewHelper.java   View source code 6 votes vote down vote up
private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scrollEventType) {
  View contentView = scrollView.getChildAt(0);

  if (contentView == null) {
    return;
  }

  ReactContext reactContext = (ReactContext) scrollView.getContext();
  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
      ScrollEvent.obtain(
          scrollView.getId(),
          scrollEventType,
          scrollView.getScrollX(),
          scrollView.getScrollY(),
          contentView.getWidth(),
          contentView.getHeight(),
          scrollView.getWidth(),
          scrollView.getHeight()));
}
 
Example 12
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
public void shutDownContext() {
  if (mInstance != null) {
    final ReactContext contextToDestroy = mReactContext;
    mReactContext = null;
    mInstance = null;

    final SimpleSettableFuture<Void> semaphore = new SimpleSettableFuture<>();
    UiThreadUtil.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        if (contextToDestroy != null) {
          contextToDestroy.destroy();
        }
        semaphore.set(null);
      }
    });
    semaphore.getOrThrow();
  }
}
 
Example 13
Project: RNLearn_Project1   File: FrescoModule.java   View source code 6 votes vote down vote up
/**
 * Get the default Fresco configuration builder.
 * Allows adding of configuration options in addition to the default values.
 *
 * @return {@link ImagePipelineConfig.Builder} that has been initialized with default values
 */
public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext context) {
  HashSet<RequestListener> requestListeners = new HashSet<>();
  requestListeners.add(new SystraceRequestListener());

  OkHttpClient client = OkHttpClientProvider.createClient();

  // make sure to forward cookies for any requests via the okHttpClient
  // so that image requests to endpoints that use cookies still work
  CookieJarContainer container = (CookieJarContainer) client.cookieJar();
  ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
  container.setCookieJar(new JavaNetCookieJar(handler));

  return OkHttpImagePipelineConfigFactory
    .newBuilder(context.getApplicationContext(), client)
    .setNetworkFetcher(new ReactOkHttpNetworkFetcher(client))
    .setDownsampleEnabled(false)
    .setRequestListeners(requestListeners);
}
 
Example 14
Project: RNLearn_Project1   File: ReactIdleDetectionUtil.java   View source code 6 votes vote down vote up
/**
 * Waits for both the UI thread and bridge to be idle. It determines this by waiting for the
 * bridge to become idle, then waiting for the UI thread to become idle, then checking if the
 * bridge is idle again (if the bridge was idle before and is still idle after running the UI
 * thread to idle, then there are no more events to process in either place).
 * <p/>
 * Also waits for any Choreographer callbacks to run after the initial sync since things like UI
 * events are initiated from Choreographer callbacks.
 */
public static void waitForBridgeAndUIIdle(
    ReactBridgeIdleSignaler idleSignaler,
    final ReactContext reactContext,
    long timeoutMs) {
  UiThreadUtil.assertNotOnUiThread();

  long startTime = SystemClock.uptimeMillis();
  waitInner(idleSignaler, timeoutMs);

  long timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
  waitForChoreographer(timeToWait);
  waitForJSIdle(reactContext);

  timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
  waitInner(idleSignaler, timeToWait);
  timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
  waitForChoreographer(timeToWait);
}
 
Example 15
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
public void shutDownContext() {
  if (mInstance != null) {
    final ReactContext contextToDestroy = mReactContext;
    mReactContext = null;
    mInstance = null;

    final SimpleSettableFuture<Void> semaphore = new SimpleSettableFuture<>();
    UiThreadUtil.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        if (contextToDestroy != null) {
          contextToDestroy.destroy();
        }
        semaphore.set(null);
      }
    });
    semaphore.getOrThrow();
  }
}
 
Example 16
Project: RNLearn_Project1   File: ReactIdleDetectionUtil.java   View source code 6 votes vote down vote up
/**
 * Waits for both the UI thread and bridge to be idle. It determines this by waiting for the
 * bridge to become idle, then waiting for the UI thread to become idle, then checking if the
 * bridge is idle again (if the bridge was idle before and is still idle after running the UI
 * thread to idle, then there are no more events to process in either place).
 * <p/>
 * Also waits for any Choreographer callbacks to run after the initial sync since things like UI
 * events are initiated from Choreographer callbacks.
 */
public static void waitForBridgeAndUIIdle(
    ReactBridgeIdleSignaler idleSignaler,
    final ReactContext reactContext,
    long timeoutMs) {
  UiThreadUtil.assertNotOnUiThread();

  long startTime = SystemClock.uptimeMillis();
  waitInner(idleSignaler, timeoutMs);

  long timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
  waitForChoreographer(timeToWait);
  waitForJSIdle(reactContext);

  timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
  waitInner(idleSignaler, timeToWait);
  timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
  waitForChoreographer(timeToWait);
}
 
Example 17
Project: RNLearn_Project1   File: ReactIdleDetectionUtil.java   View source code 6 votes vote down vote up
private static void waitForJSIdle(ReactContext reactContext) {
  if (!reactContext.hasActiveCatalystInstance()) {
    return;
  }
  final CountDownLatch latch = new CountDownLatch(1);

  reactContext.runOnJSQueueThread(
      new Runnable() {
        @Override
        public void run() {
          latch.countDown();
        }
      });

  try {
    if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
      throw new RuntimeException("Timed out waiting for JS thread");
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 18
Project: react-native-twitterkit   File: TweetView.java   View source code 5 votes vote down vote up
private void handleSuccess() {
  WritableMap evt = Arguments.createMap();

  ReactContext ctx = (ReactContext) getContext();
  ctx.getJSModule(RCTEventEmitter.class).receiveEvent(
          getId(),
          "onLoadSuccess",
          evt);
}
 
Example 19
Project: react-native-twitterkit   File: ReactTweetViewManager.java   View source code 5 votes vote down vote up
@Override
public void onSizeChanged(TweetView view, final int width, final int height) {
  Log.d(TAG, "TweetView changed size: " + width + ", " + height);
  ReactContext ctx = (ReactContext) view.getContext();
  final UIManagerModule uiManager = ctx.getNativeModule(UIManagerModule.class);
  final int reactTag = view.getReactTag();

  ctx.runOnNativeModulesQueueThread(new Runnable() {
    @Override
    public void run() {
      uiManager.updateNodeSize(reactTag, width, height);
    }
  });
}
 
Example 20
Project: react-native-collapsing-toolbar   File: AppBarLayoutManager.java   View source code 5 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    WritableMap event = Arguments.createMap();
    event.putDouble("offset", verticalOffset);
    ReactContext reactContext = (ReactContext) appBarLayout.getContext();
    reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(appBarLayout.getId(), "topOffsetChanged", event);
}
 
Example 21
Project: RNLearn_Project1   File: ReactInstanceManager.java   View source code 5 votes vote down vote up
private void tearDownReactContext(ReactContext reactContext) {
  UiThreadUtil.assertOnUiThread();
  if (mLifecycleState == LifecycleState.RESUMED) {
    reactContext.onHostPause();
  }
  for (ReactRootView rootView : mAttachedRootViews) {
    detachViewFromInstance(rootView, reactContext.getCatalystInstance());
  }
  reactContext.destroy();
  mDevSupportManager.onReactInstanceDestroyed(reactContext);
  mMemoryPressureRouter.removeMemoryPressureListener(reactContext.getCatalystInstance());
}
 
Example 22
Project: react-native-google-fit   File: StepSensor.java   View source code 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
    reactContext
            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
            .emit(eventName, params);
}
 
Example 23
Project: react-native-leancloud-sdk   File: RNPushNotificationModule.java   View source code 5 votes vote down vote up
@ReactMethod
public void requestPermissions(String leancloudAppId, String leancloudAppKey) {
    ReactContext reactContext = getReactApplicationContext();
    Intent AVService = new Intent(reactContext, RNPushNotificationRegistrationService.class);
    AVService.putExtra("leancloudAppId", leancloudAppId);
    AVService.putExtra("leancloudAppKey", leancloudAppKey);
    reactContext.startService(AVService);
}
 
Example 24
Project: RNLearn_Project1   File: ReactAppTestActivity.java   View source code 5 votes vote down vote up
private ReactContext waitForReactContext() {
  Assertions.assertNotNull(mReactInstanceManager);

  try {
    while (true) {
      ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
      if (reactContext != null) {
         return reactContext;
      }
      Thread.sleep(100);
    }
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 25
Project: RNLearn_Project1   File: ReactViewPager.java   View source code 5 votes vote down vote up
public ReactViewPager(ReactContext reactContext) {
  super(reactContext);
  mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mIsCurrentItemFromJs = false;
  setOnPageChangeListener(new PageChangeListener());
  setAdapter(new Adapter());
}
 
Example 26
Project: RNLearn_Project1   File: ImageStoreManager.java   View source code 5 votes vote down vote up
private GetBase64Task(
    ReactContext reactContext,
    String uri,
    Callback success,
    Callback error) {
  super(reactContext);
  mUri = uri;
  mSuccess = success;
  mError = error;
}
 
Example 27
Project: RNLearn_Project1   File: FlatViewGroup.java   View source code 5 votes vote down vote up
/**
 * Propogates image load events to javascript if the hosting view is still alive.
 *
 * @param reactTag The view id.
 * @param imageLoadEvent The event type.
 */
public void dispatchImageLoadEvent(int reactTag, int imageLoadEvent) {
  FlatViewGroup view = get();
  if (view == null) {
    return;
  }

  ReactContext reactContext = ((ReactContext) view.getContext());
  UIManagerModule uiManagerModule = reactContext.getNativeModule(UIManagerModule.class);
  uiManagerModule.getEventDispatcher().dispatchEvent(
      new ImageLoadEvent(reactTag, imageLoadEvent));
}
 
Example 28
Project: react-native-datepicker-component-android   File: RNDatePickerComponentViewManager.java   View source code 5 votes vote down vote up
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    ReactContext reactContext = (ReactContext) view.getContext();
    @SuppressLint("DefaultLocale") String date = String.format("%d-%d-%d", year, monthOfYear+1, dayOfMonth);
    reactContext.getNativeModule(UIManagerModule.class)
            .getEventDispatcher()
            .dispatchEvent(new RNDatePickerComponentEvent(view.getId(), date));
}
 
Example 29
Project: react-native-fused-location   File: FusedLocationModule.java   View source code 5 votes vote down vote up
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) {
    if (reactContext.hasActiveCatalystInstance()) {
        reactContext
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, params);
    } else {
        Log.i(TAG, "Waiting for CatalystInstance...");
    }
}
 
Example 30
Project: react-native-tabbed-view-pager-android   File: ReactViewPager.java   View source code 5 votes vote down vote up
public ReactViewPager(ReactContext reactContext) {
  super(reactContext);
  mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mIsCurrentItemFromJs = false;
  setOnPageChangeListener(new PageChangeListener());
  setAdapter(new Adapter());
}
 
Example 31
Project: react-native-network-connection-class   File: Module.java   View source code 5 votes vote down vote up
private void sendEvent(ReactContext reactContext,
                       String eventName,
                       WritableMap params) {
  reactContext
    .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
    .emit(eventName, params);
}
 
Example 32
Project: RNLearn_Project1   File: MainActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getReactNativeHost().getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
        @Override
        public void onReactContextInitialized(ReactContext context) {
            getWindow().getDecorView().setBackgroundColor(Color.WHITE);
        }
    });
}
 
Example 33
Project: RNLearn_Project1   File: ReactTextInputManager.java   View source code 5 votes vote down vote up
public ReactTextInputTextWatcher(
    final ReactContext reactContext,
    final ReactEditText editText) {
  mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mEditText = editText;
  mPreviousText = null;
}
 
Example 34
Project: RNLearn_Project1   File: ReactRootView.java   View source code 5 votes vote down vote up
private void dispatchJSTouchEvent(MotionEvent event) {
  if (mReactInstanceManager == null || !mIsAttachedToInstance ||
    mReactInstanceManager.getCurrentReactContext() == null) {
    FLog.w(
      ReactConstants.TAG,
      "Unable to dispatch touch to JS as the catalyst instance has not been attached");
    return;
  }
  ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
  EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class)
    .getEventDispatcher();
  mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher);
}
 
Example 35
Project: RNLearn_Project1   File: ReactAppTestActivity.java   View source code 5 votes vote down vote up
private ReactContext waitForReactContext() {
  Assertions.assertNotNull(mReactInstanceManager);

  try {
    while (true) {
      ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
      if (reactContext != null) {
         return reactContext;
      }
      Thread.sleep(100);
    }
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 36
Project: RNLearn_Project1   File: ReactSliderManager.java   View source code 5 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
  ReactContext reactContext = (ReactContext) seekbar.getContext();
  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
      new ReactSliderEvent(
          seekbar.getId(),
          ((ReactSlider) seekbar).toRealProgress(progress),
          fromUser));
}
 
Example 37
Project: RNLearn_Project1   File: ReactSliderManager.java   View source code 5 votes vote down vote up
@Override
public void onStopTrackingTouch(SeekBar seekbar) {
  ReactContext reactContext = (ReactContext) seekbar.getContext();
  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
      new ReactSlidingCompleteEvent(
          seekbar.getId(),
          ((ReactSlider) seekbar).toRealProgress(seekbar.getProgress())));
}
 
Example 38
Project: RNLearn_Project1   File: ReactImageView.java   View source code 5 votes vote down vote up
public void setShouldNotifyLoadEvents(boolean shouldNotify) {
  if (!shouldNotify) {
    mControllerListener = null;
  } else {
    final EventDispatcher mEventDispatcher = ((ReactContext) getContext()).
        getNativeModule(UIManagerModule.class).getEventDispatcher();

    mControllerListener = new BaseControllerListener<ImageInfo>() {
      @Override
      public void onSubmit(String id, Object callerContext) {
        mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_START));
      }

      @Override
      public void onFinalImageSet(
          String id,
          @Nullable final ImageInfo imageInfo,
          @Nullable Animatable animatable) {
        if (imageInfo != null) {
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD,
              mImageSource.getSource(), imageInfo.getWidth(), imageInfo.getHeight()));
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
        }
      }

      @Override
      public void onFailure(String id, Throwable throwable) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR));
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
      }
    };
  }

  mIsDirty = true;
}
 
Example 39
Project: RNLearn_Project1   File: ReactViewPager.java   View source code 5 votes vote down vote up
public ReactViewPager(ReactContext reactContext) {
  super(reactContext);
  mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  mIsCurrentItemFromJs = false;
  setOnPageChangeListener(new PageChangeListener());
  setAdapter(new Adapter());
}
 
Example 40
Project: RNLearn_Project1   File: ReactImageView.java   View source code 5 votes vote down vote up
public void setShouldNotifyLoadEvents(boolean shouldNotify) {
  if (!shouldNotify) {
    mControllerListener = null;
  } else {
    final EventDispatcher mEventDispatcher = ((ReactContext) getContext()).
        getNativeModule(UIManagerModule.class).getEventDispatcher();

    mControllerListener = new BaseControllerListener<ImageInfo>() {
      @Override
      public void onSubmit(String id, Object callerContext) {
        mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_START));
      }

      @Override
      public void onFinalImageSet(
          String id,
          @Nullable final ImageInfo imageInfo,
          @Nullable Animatable animatable) {
        if (imageInfo != null) {
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD,
              mImageSource.getSource(), imageInfo.getWidth(), imageInfo.getHeight()));
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
        }
      }

      @Override
      public void onFailure(String id, Throwable throwable) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR));
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
      }
    };
  }

  mIsDirty = true;
}