Java Code Examples for com.facebook.react.uimanager.UIManagerModule

The following are top voted examples for showing how to use com.facebook.react.uimanager.UIManagerModule. 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-andorid-shadow   File: RNReactNativeAndoridShadowModule.java   Source Code and License 6 votes vote down vote up
@ReactMethod
    public void applyShadowForView(final Integer tag, final ReadableMap param) {
        Log.d(TAG,"AndroidShadowManager applyShadowForView! tag: " + tag);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            return;
        }
        UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new UIBlock() {

            @Override
            public void execute(NativeViewHierarchyManager nvhm) {
                ReactViewGroup targetView = (ReactViewGroup) nvhm.resolveView(tag);
                Log.d(TAG,"AndroidShadowManager view w = " + targetView.getWidth() + " h = " + targetView.getHeight());
//                targetView.setBackgroundColor(Color.CYAN);
                targetView.getViewTreeObserver().addOnGlobalLayoutListener(new OutlineAdjuster(targetView,param));

            }
        });
    }
 
Example 2
Project: react-native-recyclerview-list   File: RecyclerViewBackedScrollView.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (super.onInterceptTouchEvent(ev)) {
        NativeGestureUtil.notifyNativeGestureStarted(this, ev);
        mDragging = true;
        getReactContext().getNativeModule(UIManagerModule.class).getEventDispatcher()
                .dispatchEvent(ScrollEvent.obtain(
                        getId(),
                        ScrollEventType.BEGIN_DRAG,
                        0, /* offsetX = 0, horizontal scrolling only */
                        computeVerticalScrollOffset(),
                        0, // xVelocity
                        0, // yVelocity
                        getWidth(),
                        computeVerticalScrollRange(),
                        getWidth(),
                        getHeight()));
        return true;
    }

    return false;
}
 
Example 3
Project: react-native-recyclerview-list   File: RecyclerViewBackedScrollView.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    if (action == MotionEvent.ACTION_UP && mDragging) {
        mDragging = false;
        mVelocityHelper.calculateVelocity(ev);
        getReactContext().getNativeModule(UIManagerModule.class).getEventDispatcher()
                .dispatchEvent(ScrollEvent.obtain(
                        getId(),
                        ScrollEventType.END_DRAG,
                        0, /* offsetX = 0, horizontal scrolling only */
                        computeVerticalScrollOffset(),
                        mVelocityHelper.getXVelocity(),
                        mVelocityHelper.getYVelocity(),
                        getWidth(),
                        computeVerticalScrollRange(),
                        getWidth(),
                        getHeight()));
    }
    return super.onTouchEvent(ev);
}
 
Example 4
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan[] underlineSpans =
      text.getSpans(0, text.length(), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan(textView, StrikethroughSpan.class);
  assertThat(underlineSpans).hasSize(0);
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 5
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testFontFamilyBoldItalicStyleApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(
          ViewProps.FONT_FAMILY, "sans-serif",
          ViewProps.FONT_WEIGHT, "500",
          ViewProps.FONT_STYLE, "italic"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  CustomStyleSpan customStyleSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
  assertThat(customStyleSpan.getFontFamily()).isEqualTo("sans-serif");
  assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isNotZero();
  assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero();
}
 
Example 6
Project: RNLearn_Project1   File: ReactModalHostView.java   Source Code and License 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 7
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  UnderlineSpan underlineSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 8
Project: RNLearn_Project1   File: ReactToolbarManager.java   Source Code and License 6 votes vote down vote up
@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactToolbar view) {
  final EventDispatcher mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class)
      .getEventDispatcher();
  view.setNavigationOnClickListener(
      new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          mEventDispatcher.dispatchEvent(
              new ToolbarClickEvent(view.getId(), -1));
        }
      });

  view.setOnMenuItemClickListener(
      new ReactToolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
          mEventDispatcher.dispatchEvent(
              new ToolbarClickEvent(
                  view.getId(),
                  menuItem.getOrder()));
          return true;
        }
      });
}
 
Example 9
Project: RNLearn_Project1   File: ReactScrollViewHelper.java   Source Code and License 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 10
Project: RNLearn_Project1   File: ReactTestHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @return a CatalystInstance mock that has a default working ReactQueueConfiguration.
 */
public static CatalystInstance createMockCatalystInstance() {
  ReactQueueConfigurationSpec spec = ReactQueueConfigurationSpec.builder()
      .setJSQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
      .setNativeModulesQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
      .build();
  ReactQueueConfiguration ReactQueueConfiguration = ReactQueueConfigurationImpl.create(
      spec,
      new QueueThreadExceptionHandler() {
        @Override
        public void handleException(Exception e) {
          throw new RuntimeException(e);
        }
      });

  CatalystInstance reactInstance = mock(CatalystInstance.class);
  when(reactInstance.getReactQueueConfiguration()).thenReturn(ReactQueueConfiguration);
  when(reactInstance.getNativeModule(UIManagerModule.class))
      .thenReturn(mock(UIManagerModule.class));

  return reactInstance;
}
 
Example 11
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan underlineSpan = getSingleSpan(textView, UnderlineSpan.class);
  StrikethroughSpan[] strikeThroughSpans =
      text.getSpans(0, text.length(), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpans).hasSize(0);
}
 
Example 12
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  Spanned text = (Spanned) textView.getText();
  UnderlineSpan[] underlineSpans =
      text.getSpans(0, text.length(), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan(textView, StrikethroughSpan.class);
  assertThat(underlineSpans).hasSize(0);
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 13
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testTextDecorationLineUnderlineLineThroughApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  UnderlineSpan underlineSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
  StrikethroughSpan strikeThroughSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), StrikethroughSpan.class);
  assertThat(underlineSpan instanceof UnderlineSpan).isTrue();
  assertThat(strikeThroughSpan instanceof StrikethroughSpan).isTrue();
}
 
Example 14
Project: RNLearn_Project1   File: ReactTestHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @return a CatalystInstance mock that has a default working ReactQueueConfiguration.
 */
public static CatalystInstance createMockCatalystInstance() {
  ReactQueueConfigurationSpec spec = ReactQueueConfigurationSpec.builder()
      .setJSQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
      .setNativeModulesQueueThreadSpec(MessageQueueThreadSpec.mainThreadSpec())
      .build();
  ReactQueueConfiguration ReactQueueConfiguration = ReactQueueConfigurationImpl.create(
      spec,
      new QueueThreadExceptionHandler() {
        @Override
        public void handleException(Exception e) {
          throw new RuntimeException(e);
        }
      });

  CatalystInstance reactInstance = mock(CatalystInstance.class);
  when(reactInstance.getReactQueueConfiguration()).thenReturn(ReactQueueConfiguration);
  when(reactInstance.getNativeModule(UIManagerModule.class))
      .thenReturn(mock(UIManagerModule.class));

  return reactInstance;
}
 
Example 15
Project: RNLearn_Project1   File: ReactModalHostView.java   Source Code and License 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 16
Project: RNLearn_Project1   File: ReactToolbarManager.java   Source Code and License 6 votes vote down vote up
@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactToolbar view) {
  final EventDispatcher mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class)
      .getEventDispatcher();
  view.setNavigationOnClickListener(
      new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          mEventDispatcher.dispatchEvent(
              new ToolbarClickEvent(view.getId(), -1));
        }
      });

  view.setOnMenuItemClickListener(
      new ReactToolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
          mEventDispatcher.dispatchEvent(
              new ToolbarClickEvent(
                  view.getId(),
                  menuItem.getOrder()));
          return true;
        }
      });
}
 
Example 17
Project: RNLearn_Project1   File: ReactScrollViewHelper.java   Source Code and License 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 18
Project: RNLearn_Project1   File: CoreModulesPackage.java   Source Code and License 6 votes vote down vote up
private UIManagerModule createUIManager(ReactApplicationContext reactContext) {
  ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_START);
  Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
  try {
    List<ViewManager> viewManagersList = mReactInstanceManager.createAllViewManagers(
      reactContext);
    return new UIManagerModule(
      reactContext,
      viewManagersList,
      mUIImplementationProvider,
      mLazyViewManagersEnabled);
  } finally {
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
    ReactMarker.logMarker(CREATE_UI_MANAGER_MODULE_END);
  }
}
 
Example 19
Project: react-native-twitterkit   File: ReactTweetViewManager.java   Source Code and License 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-recyclerview-list   File: RecyclerViewBackedScrollView.java   Source Code and License 5 votes vote down vote up
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);

    if (mOnScrollDispatchHelper.onScrollChanged(l, t)) {
        getReactContext().getNativeModule(UIManagerModule.class).getEventDispatcher()
                .dispatchEvent(ScrollEvent.obtain(
                        getId(),
                        ScrollEventType.SCROLL,
                        0, /* offsetX = 0, horizontal scrolling only */
                        computeVerticalScrollOffset(),
                        mOnScrollDispatchHelper.getXFlingVelocity(),
                        mOnScrollDispatchHelper.getYFlingVelocity(),
                        getWidth(),
                        computeVerticalScrollRange(),
                        getWidth(),
                        getHeight()));
    }

    final int firstIndex = ((LinearLayoutManager) getLayoutManager()).findFirstVisibleItemPosition();
    final int lastIndex = ((LinearLayoutManager) getLayoutManager()).findLastVisibleItemPosition();

    if (firstIndex != mFirstVisibleIndex || lastIndex != mLastVisibleIndex) {
        getReactContext().getNativeModule(UIManagerModule.class).getEventDispatcher()
                .dispatchEvent(new VisibleItemsChangeEvent(
                        getId(),
                        SystemClock.nanoTime(),
                        firstIndex,
                        lastIndex));

        mFirstVisibleIndex = firstIndex;
        mLastVisibleIndex = lastIndex;
    }
}
 
Example 21
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testFontFamilyStyleApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  CustomStyleSpan customStyleSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
  assertThat(customStyleSpan.getFontFamily()).isEqualTo("sans-serif");
  assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isZero();
  assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isZero();
}
 
Example 22
Project: react-native-pull-up-down-refresh   File: RCTLazyLoadViewManager.java   Source Code and License 5 votes vote down vote up
@Override
protected void addEventEmitters(
        final ThemedReactContext reactContext,
        final RCTLazyLoadView view) {
    view.setOnEvChangeListener(
            new OnEvChangeListener() {
                @Override
                public void onWindowVisibilityChange( boolean hiddenState) {
                    reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
                            .dispatchEvent(new WindowVisibilityChangeEvent(view.getId(), SystemClock.nanoTime(), hiddenState));
                }

            });
}
 
Example 23
Project: react-native-datepicker-component-android   File: RNDatePickerComponentViewManager.java   Source Code and License 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 24
Project: react-native-webgl-view-shot   File: RNWebGLTextureViewLoader.java   Source Code and License 5 votes vote down vote up
@Override
public void loadWithConfig(ReadableMap config, RNWebGLTextureCompletionBlock callback) {
    int tag = config.getInt("view");
    try {
        UIManagerModule uiManager = this.reactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new RNWebGLTextureViewUIBlock(config, tag, callback));
    }
    catch (Exception e) {
        callback.call(e, null);
    }
}
 
Example 25
Project: react-native-tabbed-view-pager-android   File: ReactViewPager.java   Source Code and License 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: ReactTextInputManager.java   Source Code and License 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 27
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testItalicFontApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.FONT_STYLE, "italic"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  CustomStyleSpan customStyleSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
  assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isNotZero();
  assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isZero();
}
 
Example 28
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Test
public void testMaxLinesApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.NUMBER_OF_LINES, 2),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  TextView textView = (TextView) rootView.getChildAt(0);
  assertThat(textView.getText().toString()).isEqualTo("test text");
  assertThat(textView.getMaxLines()).isEqualTo(2);
  assertThat(textView.getEllipsize()).isEqualTo(TextUtils.TruncateAt.END);
}
 
Example 29
Project: RNLearn_Project1   File: ReactSwitchManager.java   Source Code and License 5 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  ReactContext reactContext = (ReactContext) buttonView.getContext();
  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
      new ReactSwitchEvent(
          buttonView.getId(),
          isChecked));
}
 
Example 30
Project: RNLearn_Project1   File: ReactDrawerLayoutManager.java   Source Code and License 5 votes vote down vote up
@Override
protected void addEventEmitters(ThemedReactContext reactContext, ReactDrawerLayout view) {
  view.setDrawerListener(
      new DrawerEventEmitter(
          view,
          reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
}
 
Example 31
Project: RNLearn_Project1   File: ReactSliderManager.java   Source Code and License 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 32
Project: RNLearn_Project1   File: TextInputTest.java   Source Code and License 5 votes vote down vote up
public UIManagerModule getUIManagerModule() {
  ReactApplicationContext reactContext = ReactTestHelper.createCatalystContextForTest();
  List<ViewManager> viewManagers = Arrays.asList(
      new ViewManager[] {
          new ReactTextInputManager(),
      });
  UIManagerModule uiManagerModule = new UIManagerModule(
      reactContext,
      viewManagers,
      new UIImplementationProvider(),
      false);
  uiManagerModule.onHostResume();
  return uiManagerModule;
}
 
Example 33
Project: RNLearn_Project1   File: SwipeRefreshLayoutManager.java   Source Code and License 5 votes vote down vote up
@Override
protected void addEventEmitters(
    final ThemedReactContext reactContext,
    final ReactSwipeRefreshLayout view) {
  view.setOnRefreshListener(
      new OnRefreshListener() {
        @Override
        public void onRefresh() {
          reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
              .dispatchEvent(new RefreshEvent(view.getId()));
        }
      });
}
 
Example 34
Project: RNLearn_Project1   File: ReactPickerManager.java   Source Code and License 5 votes vote down vote up
@Override
protected void addEventEmitters(
    final ThemedReactContext reactContext,
    final ReactPicker picker) {
  picker.setOnSelectListener(
          new PickerEventEmitter(
                  picker,
                  reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
}
 
Example 35
Project: RNLearn_Project1   File: ReactViewPager.java   Source Code and License 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 36
Project: RNLearn_Project1   File: ReactImageView.java   Source Code and License 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 37
Project: RNLearn_Project1   File: ReactRootView.java   Source Code and License 5 votes vote down vote up
@Override
public void onChildStartedNativeGesture(MotionEvent androidEvent) {
  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.onChildStartedNativeGesture(androidEvent, eventDispatcher);
}
 
Example 38
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testFontFamilyBoldStyleApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_WEIGHT, "bold"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  CustomStyleSpan customStyleSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
  assertThat(customStyleSpan.getFontFamily()).isEqualTo("sans-serif");
  assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isZero();
  assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isNotZero();
}
 
Example 39
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testFontFamilyItalicStyleApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_STYLE, "italic"),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  CustomStyleSpan customStyleSpan =
      getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
  assertThat(customStyleSpan.getFontFamily()).isEqualTo("sans-serif");
  assertThat(customStyleSpan.getStyle() & Typeface.ITALIC).isNotZero();
  assertThat(customStyleSpan.getWeight() & Typeface.BOLD).isZero();
}
 
Example 40
Project: RNLearn_Project1   File: ReactTextTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testBackgroundColorStyleApplied() {
  UIManagerModule uiManager = getUIManagerModule();

  ReactRootView rootView = createText(
      uiManager,
      JavaOnlyMap.of(ViewProps.BACKGROUND_COLOR, Color.BLUE),
      JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));

  Drawable backgroundDrawable = ((TextView) rootView.getChildAt(0)).getBackground();
  assertThat(((ReactViewBackgroundDrawable) backgroundDrawable).getColor()).isEqualTo(Color.BLUE);
}