New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pass in initial arguments to instantiate native view in RCTViewManager #498

Closed
ppong opened this Issue Mar 30, 2015 · 5 comments

Comments

Projects
None yet
4 participants
@ppong

ppong commented Mar 30, 2015

I am trying to write a native module to wrap Google Maps. However, it is unclear from the documentations how to pass in initial arguments such as latitude, longitude and zoom to instantiate the view. Thanks! Any guidance would be appreciated.

#import <GoogleMaps/GoogleMaps.h>

@implementation GoogleMapManager
- (UIView *)view
{
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:15];
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    return mapView;
}
@brentvatne

This comment has been minimized.

Show comment
Hide comment
@brentvatne

brentvatne Mar 30, 2015

Collaborator

Check out the related bits from my implementation of a Video element here:

RCTVideoManager.m - this passes the props on to setX methods in RCTVideo

RCTVideo.m - this defines how the setters work

Video.ios.js - this is where we pass it in to the element itself via js.

Collaborator

brentvatne commented Mar 30, 2015

Check out the related bits from my implementation of a Video element here:

RCTVideoManager.m - this passes the props on to setX methods in RCTVideo

RCTVideo.m - this defines how the setters work

Video.ios.js - this is where we pass it in to the element itself via js.

@dvcrn

This comment has been minimized.

Show comment
Hide comment
@dvcrn

dvcrn May 8, 2015

Contributor

Can you go a bit into detail how exactly you got it working? I am also trying to implement google maps into my native react app but have problems with passing parameters to it

Contributor

dvcrn commented May 8, 2015

Can you go a bit into detail how exactly you got it working? I am also trying to implement google maps into my native react app but have problems with passing parameters to it

@brentvatne

This comment has been minimized.

Show comment
Hide comment
@brentvatne

brentvatne May 8, 2015

Collaborator

@dvcrn - can you post your code and point to the specific place where you are having a problem passing params?

Collaborator

brentvatne commented May 8, 2015

@dvcrn - can you post your code and point to the specific place where you are having a problem passing params?

@dvcrn

This comment has been minimized.

Show comment
Hide comment
@dvcrn

dvcrn May 9, 2015

Contributor

I am looking for an example in how to implement the same code @ppong mentioned above.

#import <GoogleMaps/GoogleMaps.h>

@implementation GoogleMapManager
- (UIView *)view
{
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:15];
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    return mapView;
}

I'm trying to pass a latitude, longitude and zoom value from javascript into the mapmanager so the mapmanager can instantiate the camera and mapview correctly. I read through a few finished native react modules but couldn't quite find the important bits

Contributor

dvcrn commented May 9, 2015

I am looking for an example in how to implement the same code @ppong mentioned above.

#import <GoogleMaps/GoogleMaps.h>

@implementation GoogleMapManager
- (UIView *)view
{
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:15];
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    return mapView;
}

I'm trying to pass a latitude, longitude and zoom value from javascript into the mapmanager so the mapmanager can instantiate the camera and mapview correctly. I read through a few finished native react modules but couldn't quite find the important bits

@brentvatne

This comment has been minimized.

Show comment
Hide comment
@brentvatne

brentvatne May 31, 2015

Collaborator

Similar problem was solved here on react-native-mapbox-gl

There is no way to pass in some values into a constructor, but if you move the view you are creating into something like RCTMapboxGL in the above link, then you can defer creating the underlying native component that you are wrapping until all of the necessary initialization props are available.

Collaborator

brentvatne commented May 31, 2015

Similar problem was solved here on react-native-mapbox-gl

There is no way to pass in some values into a constructor, but if you move the view you are creating into something like RCTMapboxGL in the above link, then you can defer creating the underlying native component that you are wrapping until all of the necessary initialization props are available.

@brentvatne brentvatne closed this May 31, 2015

@facebook facebook locked as resolved and limited conversation to collaborators May 31, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.