Skip to content

Commit

Permalink
fix(swift): update swift modules, take out view stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
peggyrayzis committed Jul 11, 2017
1 parent 3b352f0 commit 5d0c583
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 33 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# react-native-create-bridge
React Native bridge modules made easy! If you're a JavaScript developer writing your first lines of native code or a more experienced developer looking to eliminate boilerplate from your React Native workflow, this tool is for you.
Bridging native modules & UI components made easy! If you're a JavaScript developer writing your first lines of native code or a more experienced developer looking to eliminate boilerplate from your React Native workflow, this tool is for you.

## Getting Started
1. `npm install -g react-native-create-bridge` or `yarn global add react-native-create-bridge`
2. From the root of your React Native project, run `create-bridge`
3. The prompts will ask you for:
- Your bridge module name
- Whether you want to create a native module or UI component (or both!)
- The platforms and languages you would like to support. Currently, we default to iOS/Obj-C and Android/Java, but you can also choose iOS/Swift or Android/Kotlin if you prefer.
- The directory where you would like your JS files. If it doesn't exist, we'll create it for you.
4. That's it! 📦 Sit back and we'll deliver your native module for you lightning fast! ⚡️
Expand Down Expand Up @@ -58,7 +59,7 @@ Depending on your environment, there may be a couple more steps that you have to
## Goals
- [x] Delivers bridge module in Obj-C, Swift, Kotlin, & Java
- [x] Compatible with all versions of React Native, including v0.40+
- [ ] Split out native UI components & modules into their own templates
- [x] Split out native UI components & modules into their own templates
- [ ] Config to remove comments for more experienced users
- [ ] Modifies existing project files (`AppDelegate.h`, `MainApplication.java`) to complete the bridging process
- [ ] Your feature request could be here! Open up an issue and give us feedback 😊
Expand Down
2 changes: 1 addition & 1 deletion templates/combined/android-java/TemplateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public View createViewInstance(ThemedReactContext context){

@ReactProp(name = "exampleProp")
public void setExampleProp(View view, String prop) {
// Set properties from React onto your native component
// Set properties from React onto your native component via a setter method
// https://facebook.github.io/react-native/docs/native-components-android.html#3-expose-view-property-setters-using-reactprop-or-reactpropgroup-annotation
}
}
12 changes: 0 additions & 12 deletions templates/combined/ios-swift/Template-Bridging-Header.h

This file was deleted.

11 changes: 10 additions & 1 deletion templates/modules/ios-objc/Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#import “React/RCTBridgeModule.h” // Required when used as a Pod in a Swift project
#endif

@interface {{template}} : NSObject <RCTBridgeModule>
// import RCTEventEmitter
#if __has_include(<React/RCTEventEmitter.h>)
#import <React/RCTEventEmitter.h>
#elif __has_include(“RCTEventEmitter.h”)
#import “RCTEventEmitter.h”
#else
#import “React/RCTEventEmitter.h” // Required when used as a Pod in a Swift project
#endif

@interface {{template}} : RCTEventEmitter <RCTBridgeModule>
// Define class properties here with @property
@end
9 changes: 8 additions & 1 deletion templates/modules/ios-objc/TemplateManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ - (NSDictionary *)constantsToExport
[self.emitMessageToRN:@"EXAMPLE_EVENT" :nil]
}

// List all your events here
// https://facebook.github.io/react-native/releases/next/docs/native-modules-ios.html#sending-events-to-javascript
- (NSArray<NSString *> *)supportedEvents
{
return @[@"SampleEvent"];
}

#pragma mark - Private methods

// Implement methods that you want to export to the native module
- (void) emitMessageToRN: (NSString *)eventName :(NSDictionary *)params {
// The bridge eventDispatcher is used to send events from native to JS env
// No documentation yet on DeviceEventEmitter: https://github.com/facebook/react-native/issues/2819
[self.bridge.eventDispatcher sendAppEventWithName: eventName body: params];
[self sendEventWithName: eventName body: params];
}

@end
20 changes: 20 additions & 0 deletions templates/modules/ios-swift/Template-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Created by react-native-create-bridge
// {{template}}-Bridging-Header.h

// import RCTBridgeModule
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#elif __has_include(“RCTBridgeModule.h”)
#import “RCTBridgeModule.h”
#else
#import “React/RCTBridgeModule.h” // Required when used as a Pod in a Swift project
#endif

// import RCTEventEmitter
#if __has_include(<React/RCTEventEmitter.h>)
#import <React/RCTEventEmitter.h>
#elif __has_include(“RCTEventEmitter.h”)
#import “RCTEventEmitter.h”
#else
#import “React/RCTEventEmitter.h” // Required when used as a Pod in a Swift project
#endif
29 changes: 29 additions & 0 deletions templates/modules/ios-swift/Template.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Created by react-native-create-bridge

// import RCTBridgeModule
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#elif __has_include(“RCTBridgeModule.h”)
#import “RCTBridgeModule.h”
#else
#import “React/RCTBridgeModule.h” // Required when used as a Pod in a Swift project
#endif

// import RCTEventEmitter
#if __has_include(<React/RCTEventEmitter.h>)
#import <React/RCTEventEmitter.h>
#elif __has_include(“RCTEventEmitter.h”)
#import “RCTEventEmitter.h”
#else
#import “React/RCTEventEmitter.h” // Required when used as a Pod in a Swift project
#endif

// Export a native module
// https://facebook.github.io/react-native/docs/native-modules-ios.html#exporting-swift
@interface RCT_EXTERN_MODULE({{template}}, NSObject)

// Export methods to a native module
// https://facebook.github.io/react-native/docs/native-modules-ios.html#exporting-swift
RCT_EXTERN_METHOD(exampleMethod)

@end
16 changes: 16 additions & 0 deletions templates/modules/ios-swift/Template.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Created by react-native-create-bridge

import Foundation

@objc({{template}})
class {{template}} : NSObject {
// Export constants to use in your native module
override func constantsToExport() -> [String : Any]! {
return ["EXAMPLE_CONSTANT": "example"]
}

// Implement methods that you want to export to the native module
@objc func exampleMethod() {
// write method here
}
}
2 changes: 1 addition & 1 deletion templates/ui-components/android-java/TemplateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public View createViewInstance(ThemedReactContext context){

@ReactProp(name = "exampleProp")
public void setExampleProp(View view, String prop) {
// Set properties from React onto your native component
// Set properties from React onto your native component via a setter method
// https://facebook.github.io/react-native/docs/native-components-android.html#3-expose-view-property-setters-using-reactprop-or-reactpropgroup-annotation
}
}
2 changes: 1 addition & 1 deletion templates/ui-components/ios-objc/Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@class RCTEventDispatcher;

@interface {{template}} : UIView
// Define class properties here with @property
// Define view properties here with @property
@property (nonatomic, assign) NSString *exampleProp;

// Initializing with the event dispatcher allows us to communicate with JS
Expand Down
14 changes: 0 additions & 14 deletions templates/ui-components/ios-swift/Template-Bridging-Header.h

This file was deleted.

0 comments on commit 5d0c583

Please sign in to comment.