@Override protected PLVideoTextureView createViewInstance(ThemedReactContext reactContext) { themedReactContext = reactContext; LayoutInflater inflater=LayoutInflater.from(reactContext); mEventEmitter=reactContext.getJSModule(RCTEventEmitter.class); //plVideoTextureView=(PLVideoTextureView) inflater.inflate(R.layout.video_view,null); plVideoTextureView=new PLVideoTextureView(reactContext); plVideoTextureView.setOnPreparedListener(mOnPreparedListener); plVideoTextureView.setOnInfoListener(mOnInfoListener); plVideoTextureView.setOnErrorListener(mOnErrorListener); plVideoTextureView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); plVideoTextureView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); plVideoTextureView.setOnCompletionListener(mOnCompletionListener); plVideoTextureView.setOnSeekCompleteListener(mOnSeekCompleteListener); reactContext.addLifecycleEventListener(this);//监听LifecycleEventListener的生命周期需要添加这句 return plVideoTextureView; }
@Override protected PLVideoView createViewInstance(ThemedReactContext reactContext) { this.reactContext = reactContext; mEventEmitter = reactContext.getJSModule(RCTEventEmitter.class); mVideoView = new PLVideoView(reactContext); // Set some listeners mVideoView.setOnPreparedListener(mOnPreparedListener); mVideoView.setOnInfoListener(mOnInfoListener); mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); mVideoView.setOnCompletionListener(mOnCompletionListener); mVideoView.setOnSeekCompleteListener(mOnSeekCompleteListener); mVideoView.setOnErrorListener(mOnErrorListener); reactContext.addLifecycleEventListener(this); return mVideoView; }
@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; } }); }
@Override protected RNBottomNavigation createViewInstance(final ThemedReactContext reactContext) { final RNBottomNavigation bottomNavigation = new RNBottomNavigation(reactContext); bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { WritableMap event = Arguments.createMap(); event.putInt("selectedPosition", item.getOrder()); reactContext.getJSModule(RCTEventEmitter.class).receiveEvent( bottomNavigation.getId(), "topChange", event ); return true; } }); return bottomNavigation; }
@Override protected void addEventEmitters( final ThemedReactContext reactContext, final RCTSwipeRefreshLayout view) { view.setOnEvTouchListener( new RCTSwipeRefreshLayout.OnEvTouchListener() { @Override public void onSwipe(int movement) { reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher() .dispatchEvent(new TouchEvent(view.getId(), SystemClock.nanoTime(), movement)); } @Override public void onSwipeRefresh() { reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher() .dispatchEvent(new TouchUpEvent(view.getId(), SystemClock.nanoTime())); } }); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override public void setThemedContext(ThemedReactContext themedContext) { super.setThemedContext(themedContext); mEditText = new EditText(themedContext); // This is needed to fix an android bug since 4.4.3 which will throw an NPE in measure, // setting the layoutParams fixes it: https://code.google.com/p/android/issues/detail?id=75877 mEditText.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); setDefaultPadding(Spacing.START, mEditText.getPaddingStart()); setDefaultPadding(Spacing.TOP, mEditText.getPaddingTop()); setDefaultPadding(Spacing.END, mEditText.getPaddingEnd()); setDefaultPadding(Spacing.BOTTOM, mEditText.getPaddingBottom()); mEditText.setPadding(0, 0, 0, 0); }
@Override public void setThemedContext(ThemedReactContext themedContext) { super.setThemedContext(themedContext); // TODO #7120264: cache this stuff better mEditText = new EditText(getThemedContext()); // This is needed to fix an android bug since 4.4.3 which will throw an NPE in measure, // setting the layoutParams fixes it: https://code.google.com/p/android/issues/detail?id=75877 mEditText.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); setDefaultPadding(Spacing.START, mEditText.getPaddingStart()); setDefaultPadding(Spacing.TOP, mEditText.getPaddingTop()); setDefaultPadding(Spacing.END, mEditText.getPaddingEnd()); setDefaultPadding(Spacing.BOTTOM, mEditText.getPaddingBottom()); mEditText.setPadding(0, 0, 0, 0); }
@Override public WebRTCView createViewInstance(ThemedReactContext context) { mContext = context; WebRTCView view = new WebRTCView(context); // view.setPreserveEGLContextOnPause(true); // view.setKeepScreenOn(true); return view; }
@Override public TweetView createViewInstance(ThemedReactContext context) { ImageLoaderFix.apply(context); TweetView tweetView = createTweetView(context); tweetView.addSizeChangeListener(this); return tweetView; }
@Override public FrameLayout createViewInstance(ThemedReactContext context) { FrameLayout view = new FrameLayout(context); CollapsingToolbarLayout.LayoutParams params = new CollapsingToolbarLayout.LayoutParams( CollapsingToolbarLayout.LayoutParams.MATCH_PARENT, CollapsingToolbarLayout.LayoutParams.WRAP_CONTENT ); params.setCollapseMode(CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PARALLAX); view.setLayoutParams(params); return view; }
@Override protected void addEventEmitters(ThemedReactContext reactContext, ReactDrawerLayout view) { view.setDrawerListener( new DrawerEventEmitter( view, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher())); }
@Override protected PLVideoView createViewInstance(ThemedReactContext reactContext) { this.reactContext = reactContext; mEventEmitter = reactContext.getJSModule(RCTEventEmitter.class); mVideoView = new PLVideoView(reactContext); // Set some listeners mVideoView.setOnPreparedListener(mOnPreparedListener); mVideoView.setOnInfoListener(mOnInfoListener); mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); mVideoView.setOnCompletionListener(mOnCompletionListener); mVideoView.setOnSeekCompleteListener(mOnSeekCompleteListener); mVideoView.setOnErrorListener(mOnErrorListener); reactContext.addLifecycleEventListener(this); mProgressUpdateRunnable=new Runnable() { @Override public void run() { if(mVideoView.isPlaying()){ WritableMap event = Arguments.createMap(); event.putDouble("currentTime", mVideoView.getCurrentPosition()/1000); mEventEmitter.receiveEvent(getTargetId(), PiliPlayerViewManager.Events.PROGRESS.toString(), event); mProgressUpdateHandler.postDelayed(mProgressUpdateRunnable,1000); } } }; return mVideoView; }
@Override protected PLVideoView createViewInstance(ThemedReactContext reactContext) { this.reactContext = reactContext; mEventEmitter = reactContext.getJSModule(RCTEventEmitter.class); mVideoView = new PLVideoView(reactContext); // Set some listeners mVideoView.setOnPreparedListener(mOnPreparedListener); mVideoView.setOnInfoListener(mOnInfoListener); mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); mVideoView.setOnCompletionListener(mOnCompletionListener); mVideoView.setOnSeekCompleteListener(mOnSeekCompleteListener); mVideoView.setOnErrorListener(mOnErrorListener); reactContext.addLifecycleEventListener(this); mProgressUpdateRunnable=new Runnable() { @Override public void run() { if(mVideoView.isPlaying()){ WritableMap event = Arguments.createMap(); event.putDouble("currentTime", mVideoView.getCurrentPosition()/1000); event.putDouble("totalTime", mVideoView.getDuration()/1000); //TODO:mBufferUpdateRunnable mEventEmitter.receiveEvent(getTargetId(), Events.PROGRESS.toString(), event); mProgressUpdateHandler.postDelayed(mProgressUpdateRunnable,1000); } } }; return mVideoView; }
@Override protected MaterialCalendarView createViewInstance(ThemedReactContext reactContext) { MaterialCalendarView materialCalendarView = new MaterialCalendarView(reactContext); materialCalendarView.setSelectedDate(new Date()); onReceiveNativeEvent(reactContext, materialCalendarView); return materialCalendarView; }
@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(); }
@Override protected WaveView createViewInstance(final ThemedReactContext reactContext) { mContext = reactContext; final WaveView waveview = new WaveView(reactContext); mWaveHelper = new WaveHelper(waveview); waveview.setWaterLevelRatio(30/100); waveview.setShapeType(WaveView.ShapeType.CIRCLE); waveview.setWaveColor( Color.parseColor("#28f16d7a"), Color.parseColor("#3cf16d7a")); waveview.setBorder(mBorderWidth, mBorderColor); mWaveHelper.start(); return waveview; }
@Override public BarcodePicker createViewInstance(ThemedReactContext context) { // Store event dispatcher for emission of events eventDispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher(); nativeAppEventEmitter = context.getJSModule(RCTNativeAppEventEmitter.class); // BarcodePicker extends View picker = new BarcodePicker(context, scanSettings); // Tell picker to call our didScan method on scan picker.setOnScanListener(this); return picker; }
@Override protected WebView createViewInstance(ThemedReactContext reactContext) { ReactWebView webView = new ReactWebView(reactContext); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage message) { if (ReactBuildConfig.DEBUG) { return super.onConsoleMessage(message); } // Ignore console logs in non debug builds. return true; } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } }); reactContext.addLifecycleEventListener(webView); mWebViewConfig.configWebView(webView); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setDisplayZoomControls(false); webView.getSettings().setDomStorageEnabled(true); // Fixes broken full-screen modals/galleries due to body height being 0. webView.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } return webView; }
@Override public void onProgress(String key, long bytesRead, long expectedLength) { List<ImageViewWithUrl> viewsForKey = VIEWS_FOR_URLS.get(key); if (viewsForKey != null) { for (ImageViewWithUrl view: viewsForKey) { WritableMap event = new WritableNativeMap(); event.putInt("loaded", (int) bytesRead); event.putInt("total", (int) expectedLength); ThemedReactContext context = (ThemedReactContext) view.getContext(); RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class); int viewId = view.getId(); eventEmitter.receiveEvent(viewId, REACT_ON_PROGRESS_EVENT, event); } } }
@Override public ReactImageView createViewInstance(ThemedReactContext context) { return new ReactImageView( context, getDraweeControllerBuilder(), getCallerContext()); }
@Override public void addRootView( int tag, SizeMonitoringFrameLayout view, ThemedReactContext themedContext) { FlatViewGroup root = new FlatViewGroup(themedContext); view.addView(root); // When unmounting, ReactInstanceManager.detachViewFromInstance() will check id of the // top-level View (SizeMonitoringFrameLayout) and pass it back to JS. We want that View's id to // be set, otherwise NativeViewHierarchyManager will not be able to cleanup properly. view.setId(tag); addRootViewGroup(tag, root, themedContext); }
@Override public void setThemedContext(ThemedReactContext themedContext) { super.setThemedContext(themedContext); if (mReactShadowNode != null) { mReactShadowNode.setThemedContext(themedContext); } }
@Override public ReactEditText createViewInstance(ThemedReactContext context) { ReactEditText editText = new ReactEditText(context); int inputType = editText.getInputType(); editText.setInputType(inputType & (~InputType.TYPE_TEXT_FLAG_MULTI_LINE)); editText.setReturnKeyType("done"); editText.setTextSize( TypedValue.COMPLEX_UNIT_PX, (int) Math.ceil(PixelUtil.toPixelFromSP(ViewDefaults.FONT_SIZE_SP))); return editText; }
@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())); }
@Before public void setup() { mContext = new ReactApplicationContext(RuntimeEnvironment.application); mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance(); mContext.initializeWithInstance(mCatalystInstanceMock); mThemedContext = new ThemedReactContext(mContext, mContext); mManager = new ReactTextInputManager(); DisplayMetricsHolder.setWindowDisplayMetrics(new DisplayMetrics()); }
@Before public void setup() { mContext = new ReactApplicationContext(RuntimeEnvironment.application); mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance(); mContext.initializeWithInstance(mCatalystInstanceMock); mThemeContext = new ThemedReactContext(mContext, mContext); Fresco.initialize(mContext); DisplayMetricsHolder.setWindowDisplayMetrics(new DisplayMetrics()); }
@Override protected ReactExoplayerView createViewInstance(ThemedReactContext themedReactContext) { return new ReactExoplayerView(themedReactContext); }
@Override public View createViewInstance(ThemedReactContext context) { throw new IllegalStateException("RCTTextInlineImage doesn't map into a native view"); }