OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 React Native 组件的 UIImagePickerController 覆盖 View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:56
标题: ios - 使用 React Native 组件的 UIImagePickerController 覆盖 View

我想使用 React Native 组件定义一个 UIImagePickerController 覆盖 View 。我正在设置为 Marc Shilling 精彩 react-native-image-picker 添加一个新选项.我希望 ImagePickerManager.launchCamera 函数将 和子项作为其参数之一,渲染它,并将其传递给 UIImagePickerController.cameraOverlayView。我已经走到这一步了:

在 ImagePickerManager.m 中:

NSNumber *viewTag = [self.options valueForKey"overlayNode"];
if (![viewTag isEqual:[NSNull null]] && viewTag != 0) {
    UIView *view = [_bridge.uiManager viewForReactTag:viewTag];
    [self.picker setCameraOverlayView:view];
}

但这需要我在 JS 端做一些扭曲才能得到一个组件实例。

React.createClass({
    render: function() { 
        return (
            <View>
                <TouchableHighlight onPress={this._showCamera}><Text>Camera</Text></TouchableHighlight>
                <View ref="foo"><Text>On top of the camera!</Text></View>
            </View>
        );
    },
    _showCamera: function() {
        var options = {
            overlayNode: React.findNodeHandle(this.refs.foo),
        };
        ImagePickerManager.launchCamera(options, (response)  => {

        });
    }
});

如果我尝试说 overlayNode: React.findNodeHandle(On top of the camera!),我会得到一个红框>.

我尝试创建一个新的 RCTRootView 并通过 AppRegistry.registerComponent 注册覆盖,但我没有看到任何实际呈现在屏幕上的内容。

NSString *overlayRootName = [self.options valueForKey"overlayComponentName"];
if (![overlayRootName isEqual:[NSNull null]] && overlayRootName.length != 0) {
    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleNameverlayRootName initialProperties:nil];
    [self.picker setCameraOverlayView:rootView];
}

我在这里错过了什么?



Best Answer-推荐答案


后一种解决方案(声明一个替代的 RCTRootView)最终成为了对我有用的解决方案。我遇到的问题是,由于某种原因,我通过添加 @synthesize bridge = _bridge;ImagePickerManager 中获得的桥在 中使用时没有呈现任何内容initWithBridge.

相反,我在我的 AppDelegate 中添加了一个字段,以公开在 application: didFinishLaunchingWithOptions: 中创建的桥接器,这很像 in this hybrid app example .当我在 initWithBridge 中使用 that 桥时,覆盖层会呈现在屏幕上。还要确保将 rootView.framerootView.backgroundColor 显式设置为透明。

Screenshot of UIImagePicker with React Native Overlay

关于ios - 使用 React Native 组件的 UIImagePickerController 覆盖 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36567545/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4