React Native原生iOS组件为空

时间:2016-12-09 19:39:40

标签: objective-c react-native react-native-ios

我创建了一个新项目,并遵循本机iOS UI组件(https://facebook.github.io/react-native/docs/native-components-ios.html)的教程。但是,当我编译并运行我的代码时,它只是一个空白屏幕。我没有看到任何错误。

我知道正在调用我的原生view方法,但我不确定为什么MKMapView没有被渲染。

index.ios.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
const MapView = require('./MapView.ios');

export default class NativeTest extends Component {
  render() {
    return (
      <View style={styles.container}>
        <MapView />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    // backgroundColor: 'blue',
  },
});

AppRegistry.registerComponent('NativeTest', () => NativeTest);

MapView.ios.js

// @flow

import { requireNativeComponent } from 'react-native';
module.exports = requireNativeComponent('RCTMapView');

RCTMapViewManager.m

// RCTMapViewManager.m
#import <MapKit/MapKit.h>

#import "RCTViewManager.h"

@interface RCTMapViewManager : RCTViewManager
@end

@implementation RCTMapViewManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
  return [[MKMapView alloc] init];
}

@end

如何在我的React Native应用程序中呈现返回的UIView

1 个答案:

答案 0 :(得分:1)

我通过从容器中移除alignItemsjustifyContent样式并向flex: 1添加MapView样式来修复它。