访问ReactNative上的所有本机视图

时间:2017-05-31 22:38:17

标签: java android react-native

我需要访问android中的所有UiComponent NativeViews,在ios中我能够使用以下代码,但在Android上我无法获得“ViewRegistry”。

[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {

    for (NSNumber *viewIndex in [viewRegistry allKeys]) {
        if(viewIndex != reactTag){
            if ([viewRegistry[viewIndex] isKindOfClass:[CDTRNJWPlayerView class]]) {
                CDTRNJWPlayerView *JWPlayerView = (CDTRNJWPlayerView*) viewRegistry[viewIndex];
                [JWPlayerView JWPlayerPause];
            }
        }
    }

}];

这里我在android模块中,你可以看到我只能用resolveViewManager方法得到当前的istance,我不能像我在Obj-c中那样做

UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);

    uiManager.addUIBlock(new UIBlock() {
        public void execute (NativeViewHierarchyManager nvhm) {

            CDTRNJWPlayerComponent jwplayerComponent = (CDTRNJWPlayerComponent) nvhm.resolveView(reactTag);
            CDTRNJWPlayerManager jwplayerManager = (CDTRNJWPlayerManager) nvhm.resolveViewManager(reactTag);
            JWPlayerView jwplayerView = (JWPlayerView) jwplayerComponent.getChildAt(0);
            jwplayerManager.pause(jwplayerView);

        }
    });

0 个答案:

没有答案