├── ReactNative
├── StructsAndEnums.cs
├── libReactNative.linkwith.cs
├── package.json
├── ApiDefinition.cs
├── Properties
│ └── AssemblyInfo.cs
├── buildLibs.sh
└── ReactNative.csproj
├── .gitignore
├── SampleApp
├── Entitlements.plist
├── Main.cs
├── Info.plist
├── Resources
│ ├── Images.xcassets
│ │ └── AppIcons.appiconset
│ │ │ └── Contents.json
│ └── LaunchScreen.xib
├── AppDelegate.cs
└── SampleApp.csproj
├── README.md
├── LICENSE
└── XamarinReactNative.sln
/ReactNative/StructsAndEnums.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ReactNative
4 | {
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /**/node_modules
2 | /**/bin
3 | /**/obj
4 | ReactNative/libReactNative.a
5 | *.userprefs
6 |
--------------------------------------------------------------------------------
/SampleApp/Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/ReactNative/libReactNative.linkwith.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ObjCRuntime;
3 |
4 | [assembly: LinkWith (
5 | "libReactNative.a",
6 | LinkTarget.ArmV7 | LinkTarget.Arm64 | LinkTarget.Simulator | LinkTarget.Simulator64,
7 | Frameworks = "JavaScriptCore QuartzCore",
8 | SmartLink = true, ForceLoad = true)]
9 |
--------------------------------------------------------------------------------
/ReactNative/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-lib",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Charles Luxton",
10 | "license": "MIT",
11 | "dependencies": {
12 | "react-native": "0.8.0"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ReactNative/ApiDefinition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using UIKit;
4 | using Foundation;
5 | using ObjCRuntime;
6 | using CoreGraphics;
7 |
8 | namespace ReactNative
9 | {
10 | [BaseType(typeof(UIView))]
11 | interface RCTRootView {
12 | [ExportAttribute("initWithBundleURL:moduleName:launchOptions:")]
13 | IntPtr Constructor(NSUrl bundleUrl, NSString moduleName, NSDictionary launchOptions);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/SampleApp/Main.cs:
--------------------------------------------------------------------------------
1 | using UIKit;
2 |
3 | namespace SampleApp
4 | {
5 | public class Application
6 | {
7 | // This is the main entry point of the application.
8 | static void Main (string[] args)
9 | {
10 | // if you want to use a different Application Delegate class from "AppDelegate"
11 | // you can specify it here.
12 | UIApplication.Main (args, null, "AppDelegate");
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ###Xamarin + React Native sample project
2 | ##Getting started
3 | These instructions assume you already have a react native project setup and your javascript bundle is available on `http://localhost:8081/index.ios.bundle`
4 |
5 | This will only work on a simulator, to run from a device you will need to update the url inside `SampleApp/AppDelegate.cs`
6 |
7 | To build the application you will first need to download React Native & build the static library for Xamarin to use.
8 |
9 | After checking out the project run the following commands:
10 |
11 | ```
12 |
13 | cd /ReactNative
14 | npm install
15 |
16 | chmod +x ./buildLibs.sh
17 | ./buildLibs.sh
18 |
19 | ```
20 |
21 | After you have done this, you can load the project in xamarin studio and deploy to a device or simulator.
22 |
23 | ##TODO
24 | The sample application only works on a simulator. Physical devices run into this error:
25 |
26 | ```
27 |
28 | [error][tid:com.facebook.React.JavaScript] 'Error: undefined is not an object (evaluating \'t("NativeModules").UIManager.RCTDatePicker.Constants\')\n
29 |
30 | ```
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/ReactNative/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | using Foundation;
5 |
6 | // This attribute allows you to mark your assemblies as “safe to link”.
7 | // When the attribute is present, the linker—if enabled—will process the assembly
8 | // even if you’re using the “Link SDK assemblies only” option, which is the default for device builds.
9 |
10 | [assembly: LinkerSafe]
11 |
12 | // Information about this assembly is defined by the following attributes.
13 | // Change them to the values specific to your project.
14 |
15 | [assembly: AssemblyTitle ("ReactNative")]
16 | [assembly: AssemblyDescription ("")]
17 | [assembly: AssemblyConfiguration ("")]
18 | [assembly: AssemblyCompany ("")]
19 | [assembly: AssemblyProduct ("")]
20 | [assembly: AssemblyCopyright ("charles")]
21 | [assembly: AssemblyTrademark ("")]
22 | [assembly: AssemblyCulture ("")]
23 |
24 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
25 | // The form "{Major}.{Minor}.*" will automatically update the build and revision,
26 | // and "{Major}.{Minor}.{Build}.*" will update just the revision.
27 |
28 | [assembly: AssemblyVersion ("1.0.*")]
29 |
30 | // The following attributes are used to specify the signing key for the assembly,
31 | // if desired. See the Mono documentation for more information about signing.
32 |
33 | //[assembly: AssemblyDelaySign(false)]
34 | //[assembly: AssemblyKeyFile("")]
35 |
--------------------------------------------------------------------------------
/ReactNative/buildLibs.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3 |
4 | function buildLib {
5 | PROJECT=$DIR/node_modules/react-native/$1
6 | echo $PROJECT
7 | rm -Rf $PROJECT/**/*.a
8 | cd $PROJECT
9 | xcodebuild \
10 | -target $2 \
11 | -sdk iphonesimulator \
12 | -configuration Release clean build
13 | xcodebuild \
14 | -target $2 \
15 | -sdk iphoneos \
16 | -arch armv7 \
17 | -configuration Release clean build
18 | xcodebuild \
19 | -target $2 \
20 | -sdk iphoneos \
21 | -arch arm64 \
22 | -configuration Release clean build \
23 | TARGET_BUILD_DIR='./build-arm64' \
24 | BUILT_PRODUCTS_DIR='./build-arm64'
25 | cd $DIR
26 | lipo -create -output $DIR/bin/react/lib$2.a \
27 | $PROJECT/build/Release-iphoneos/lib$2.a \
28 | $PROJECT/build-arm64/lib$2.a \
29 | $PROJECT/build/Release-iphonesimulator/lib$2.a
30 | }
31 |
32 | #clean .a directory
33 | rm -Rf $DIR/bin/react/**/*.a
34 | mkdir $DIR/bin/react/
35 |
36 | buildLib React React
37 | buildLib Libraries/Image RCTImage
38 | buildLib Libraries/Text RCTText
39 | buildLib Libraries/ActionSheetIOS RCTActionSheet
40 | buildLib Libraries/LinkingIOS RCTLinking
41 |
42 | cd $DIR
43 | rm -f $DIR/libReactNative.a
44 | libtool -static -o libReactNative.a \
45 | $DIR/bin/react/libReact.a \
46 | $DIR/bin/react/libRCTImage.a \
47 | $DIR/bin/react/libRCTText.a \
48 | $DIR/bin/react/libRCTActionSheet.a \
49 | $DIR/bin/react/libRCTLinking.a
50 |
--------------------------------------------------------------------------------
/SampleApp/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDisplayName
6 | XamarinReactNative
7 | CFBundleIdentifier
8 | cluxton.sample.xamarinreactnative
9 | CFBundleShortVersionString
10 | 1.0
11 | CFBundleVersion
12 | 1.0
13 | LSRequiresIPhoneOS
14 |
15 | MinimumOSVersion
16 | 8.0
17 | UIDeviceFamily
18 |
19 | 1
20 | 2
21 |
22 | UILaunchStoryboardName
23 | LaunchScreen
24 | UIRequiredDeviceCapabilities
25 |
26 | armv7
27 |
28 | UISupportedInterfaceOrientations
29 |
30 | UIInterfaceOrientationPortrait
31 | UIInterfaceOrientationLandscapeLeft
32 | UIInterfaceOrientationLandscapeRight
33 |
34 | UISupportedInterfaceOrientations~ipad
35 |
36 | UIInterfaceOrientationPortrait
37 | UIInterfaceOrientationLandscapeLeft
38 | UIInterfaceOrientationLandscapeRight
39 |
40 | XSAppIconAssets
41 | Resources/Images.xcassets/AppIcons.appiconset
42 |
43 |
44 |
--------------------------------------------------------------------------------
/XamarinReactNative.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "SampleApp\SampleApp.csproj", "{9B697011-40F0-42E1-8101-0FDA2FA8A8DF}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNative", "ReactNative\ReactNative.csproj", "{05FF3726-ED02-4814-AF63-9BA10085090E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|iPhoneSimulator = Debug|iPhoneSimulator
11 | Release|iPhone = Release|iPhone
12 | Release|iPhoneSimulator = Release|iPhoneSimulator
13 | Debug|iPhone = Debug|iPhone
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Debug|iPhone.ActiveCfg = Debug|Any CPU
17 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Debug|iPhone.Build.0 = Debug|Any CPU
18 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
19 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
20 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Release|iPhone.ActiveCfg = Release|Any CPU
21 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Release|iPhone.Build.0 = Release|Any CPU
22 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
23 | {05FF3726-ED02-4814-AF63-9BA10085090E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
24 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Debug|iPhone.ActiveCfg = Debug|iPhone
25 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Debug|iPhone.Build.0 = Debug|iPhone
26 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
27 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
28 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Release|iPhone.ActiveCfg = Release|iPhone
29 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Release|iPhone.Build.0 = Release|iPhone
30 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
31 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
32 | EndGlobalSection
33 | EndGlobal
34 |
--------------------------------------------------------------------------------
/SampleApp/Resources/Images.xcassets/AppIcons.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images": [
3 | {
4 | "size": "29x29",
5 | "scale": "1x",
6 | "idiom": "iphone"
7 | },
8 | {
9 | "size": "29x29",
10 | "scale": "2x",
11 | "idiom": "iphone"
12 | },
13 | {
14 | "size": "29x29",
15 | "scale": "3x",
16 | "idiom": "iphone"
17 | },
18 | {
19 | "size": "40x40",
20 | "scale": "2x",
21 | "idiom": "iphone"
22 | },
23 | {
24 | "size": "40x40",
25 | "scale": "3x",
26 | "idiom": "iphone"
27 | },
28 | {
29 | "size": "57x57",
30 | "scale": "1x",
31 | "idiom": "iphone"
32 | },
33 | {
34 | "size": "57x57",
35 | "scale": "2x",
36 | "idiom": "iphone"
37 | },
38 | {
39 | "size": "60x60",
40 | "scale": "2x",
41 | "idiom": "iphone"
42 | },
43 | {
44 | "size": "60x60",
45 | "scale": "3x",
46 | "idiom": "iphone"
47 | },
48 | {
49 | "size": "29x29",
50 | "scale": "1x",
51 | "idiom": "ipad"
52 | },
53 | {
54 | "size": "29x29",
55 | "scale": "2x",
56 | "idiom": "ipad"
57 | },
58 | {
59 | "size": "40x40",
60 | "scale": "1x",
61 | "idiom": "ipad"
62 | },
63 | {
64 | "size": "40x40",
65 | "scale": "2x",
66 | "idiom": "ipad"
67 | },
68 | {
69 | "size": "50x50",
70 | "scale": "1x",
71 | "idiom": "ipad"
72 | },
73 | {
74 | "size": "50x50",
75 | "scale": "2x",
76 | "idiom": "ipad"
77 | },
78 | {
79 | "size": "72x72",
80 | "scale": "1x",
81 | "idiom": "ipad"
82 | },
83 | {
84 | "size": "72x72",
85 | "scale": "2x",
86 | "idiom": "ipad"
87 | },
88 | {
89 | "size": "76x76",
90 | "scale": "1x",
91 | "idiom": "ipad"
92 | },
93 | {
94 | "size": "76x76",
95 | "scale": "2x",
96 | "idiom": "ipad"
97 | },
98 | {
99 | "size": "120x120",
100 | "scale": "1x",
101 | "idiom": "car"
102 | }
103 | ],
104 | "info": {
105 | "version": 1,
106 | "author": "xcode"
107 | }
108 | }
--------------------------------------------------------------------------------
/ReactNative/ReactNative.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {8FFB629D-F513-41CE-95D2-7ECE97B6EEEC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
7 | {05FF3726-ED02-4814-AF63-9BA10085090E}
8 | Library
9 | ReactNative
10 | Resources
11 | ReactNative
12 |
13 |
14 | true
15 | full
16 | false
17 | bin\Debug
18 | DEBUG;
19 | prompt
20 | 4
21 | false
22 | true
23 |
24 |
25 | full
26 | true
27 | bin\Release
28 | prompt
29 | 4
30 | false
31 | true
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | libReactNative.a
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/SampleApp/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 | using UIKit;
3 | using ReactNative;
4 |
5 | namespace SampleApp
6 | {
7 | // The UIApplicationDelegate for the application. This class is responsible for launching the
8 | // User Interface of the application, as well as listening (and optionally responding) to application events from iOS.
9 | [Register ("AppDelegate")]
10 | public class AppDelegate : UIApplicationDelegate
11 | {
12 | // class-level declarations
13 |
14 | public override UIWindow Window {
15 | get;
16 | set;
17 | }
18 |
19 | public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
20 | {
21 | // create a new window instance based on the screen size
22 | Window = new UIWindow (UIScreen.MainScreen.Bounds);
23 |
24 | // If you have defined a root view controller, set it here:
25 | // Window.RootViewController = myViewController;
26 |
27 | var options = new NSDictionary ();
28 |
29 | var url = NSBundle.MainBundle.GetUrlForResource ("main", "jsbundle");
30 | //var url = NSUrl.FromString("http://192.168.0.11:8081/index.ios.bundle");
31 |
32 | RCTRootView rct = new RCTRootView(url, new NSString("ReactNative"), options);
33 | var vc = new UIViewController ();
34 | vc.View = rct;
35 | vc.Init ();
36 | Window.RootViewController = vc;
37 |
38 | // make the window visible
39 | Window.MakeKeyAndVisible ();
40 |
41 | return true;
42 | }
43 |
44 | public override void OnResignActivation (UIApplication application)
45 | {
46 | // Invoked when the application is about to move from active to inactive state.
47 | // This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message)
48 | // or when the user quits the application and it begins the transition to the background state.
49 | // Games should use this method to pause the game.
50 | }
51 |
52 | public override void DidEnterBackground (UIApplication application)
53 | {
54 | // Use this method to release shared resources, save user data, invalidate timers and store the application state.
55 | // If your application supports background exection this method is called instead of WillTerminate when the user quits.
56 | }
57 |
58 | public override void WillEnterForeground (UIApplication application)
59 | {
60 | // Called as part of the transiton from background to active state.
61 | // Here you can undo many of the changes made on entering the background.
62 | }
63 |
64 | public override void OnActivated (UIApplication application)
65 | {
66 | // Restart any tasks that were paused (or not yet started) while the application was inactive.
67 | // If the application was previously in the background, optionally refresh the user interface.
68 | }
69 |
70 | public override void WillTerminate (UIApplication application)
71 | {
72 | // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground.
73 | }
74 | }
75 | }
76 |
77 |
78 |
--------------------------------------------------------------------------------
/SampleApp/Resources/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
21 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/SampleApp/SampleApp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | iPhoneSimulator
6 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
7 | {9B697011-40F0-42E1-8101-0FDA2FA8A8DF}
8 | Exe
9 | SampleApp
10 | Resources
11 | SampleApp
12 |
13 |
14 | true
15 | full
16 | false
17 | bin\iPhoneSimulator\Debug
18 | DEBUG;
19 | prompt
20 | 4
21 | false
22 | i386
23 | true
24 | true
25 | iPhone Developer
26 | true
27 |
28 |
29 | None
30 |
31 |
32 | full
33 | true
34 | bin\iPhone\Release
35 | prompt
36 | 4
37 | Entitlements.plist
38 | ARMv7, ARM64
39 | false
40 | iPhone Developer
41 |
42 |
43 | full
44 | true
45 | bin\iPhoneSimulator\Release
46 | prompt
47 | 4
48 | i386
49 | false
50 | None
51 |
52 |
53 | true
54 | full
55 | false
56 | bin\iPhone\Debug
57 | DEBUG;
58 | prompt
59 | 4
60 | false
61 | ARMv7, ARM64
62 | Entitlements.plist
63 | true
64 | iPhone Developer
65 | true
66 | true
67 | None
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | {05FF3726-ED02-4814-AF63-9BA10085090E}
95 | ReactNative
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------