原生组件不会出现在javascript端

时间:2017-03-26 07:00:28

标签: javascript ios swift react-native

我尝试使用swift创建RCTMap示例。 我可以从javascript访问我的自定义组件,但地图没有出现,我得到空白的白色视图。

MyMapManager.swift:

import Foundation

@objc(MyMapManager)
class MyMapManager: RCTViewManager {

    override func view() -> UIView! {
      let location = CLLocationCoordinate2D(
      latitude: 51.50007773,
      longitude: -0.1246402
    )
    let span = MKCoordinateSpanMake(0.05, 0.05)
    let region = MKCoordinateRegion(center: location, span: span)
    let mapView = MKMapView()
    mapView.region = region
    let test = UIView()
    mapView.frame = test.frame
    test.addSubview(mapView)
    self.view().addSubview(test)
    NSLog("***************************")
    NSLog("%@", self.view())
    return self.view()
  }

}

MyMapManagerBridge.m:

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>

@interface RCT_EXTERN_MODULE(MyMapManager, RCTViewManager)

  RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL)

@end

-Bridging-Header.h:

#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTRootView.h>
#import <MapKit/MapKit.h>
#import <React/RCTViewManager.h>

index.ios.js:

import React, { Component } from 'react';
import {
  .
  .
  .
  requireNativeComponent
} from 'react-native';
const MyMap = requireNativeComponent('MyMap', null);

export default class SwiftBridge extends Component {
  render() {
    return (
      <View style={styles.container}>
        <MyMap style={{flex: 1, backgroundColor: 'red'}} />
      </View>
    );
  }
}

这里是console.dir const:{/ p>的MyMap结果

MyMap log

0 个答案:

没有答案