@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)); } }); }
@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; }
@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); }
@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(); }
@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(); }
@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); } }); } }
@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(); }
@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; } }); }
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())); }
/** * @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; }
@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); }
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); } }
@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); } }); }
@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; } }
@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(); }
@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)); } }); }
@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)); }
@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); } }
public ReactViewPager(ReactContext reactContext) { super(reactContext); mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher(); mIsCurrentItemFromJs = false; setOnPageChangeListener(new PageChangeListener()); setAdapter(new Adapter()); }
public ReactTextInputTextWatcher( final ReactContext reactContext, final ReactEditText editText) { mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher(); mEditText = editText; mPreviousText = null; }
@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(); }
@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); }
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ReactContext reactContext = (ReactContext) buttonView.getContext(); reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent( new ReactSwitchEvent( buttonView.getId(), isChecked)); }
@Override protected void addEventEmitters(ThemedReactContext reactContext, ReactDrawerLayout view) { view.setDrawerListener( new DrawerEventEmitter( view, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher())); }
@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)); }
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; }
@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())); } }); }
@Override protected void addEventEmitters( final ThemedReactContext reactContext, final ReactPicker picker) { picker.setOnSelectListener( new PickerEventEmitter( picker, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher())); }
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; }
@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); }
@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(); }
@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(); }
@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); }