How to run React-Native Examples?

后端 未结 9 2157
暗喜
暗喜 2021-01-31 21:18

I can\'t find any instructions on how to install and run one of the other Examples provided in \'https://github.com/facebook/react-native/tree/master/Examples\' such as \'https:

9条回答
  •  一生所求
    2021-01-31 21:54

    It should work just by following the Getting Started Tutorial, except that you have to run npm install inside your react-native directory.

    Then just run for example the Movie Project with Xcode.

    If you want to "isolate" the MovieProject or another react-native example project, the easy way is to init a new react native app (react-native init MyAppName) and just copy the JS files from the example project (in the example below the Movie Project) into the new app folder.

    And then don't forget to edit your iOS/AppDelegate.m file.

    You have to edit 2 lines:

    jsCodeLocation = [NSURL URLWithString:@"http:/localhost:8081/index.ios.bundle"];
    

    By:

    jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/MoviesApp.bundle"];
    

    AND

    RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"MyAppName"
                                                   launchOptions:launchOptions];
    

    By:

    RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"MoviesApp"
                                                   launchOptions:launchOptions];
    

提交回复
热议问题