WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 1c7f310

Browse files
committed
chore(rnmbxcodegen): add codegen to generate rn boilerplate
1 parent 54ae81d commit 1c7f310

File tree

11 files changed

+281
-38
lines changed

11 files changed

+281
-38
lines changed

ios/RNMBX/RNMBXLocation.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/***
2+
to: ios/rnmbx/RNMBXLocation.swift
3+
userEditable: true
4+
***/
5+
16
@objc(RNMBXLocation)
27
open class RNMBXLocation : RNMBXMapComponentBase {
3-
}
8+
9+
10+
@objc
11+
public static func someMethod(_ view: RNMBXLocation, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
12+
// TODO implement
13+
}
14+
15+
}

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@sinonjs/fake-timers": "^8.0.1",
9292
"@testing-library/react-native": "^12.4.0",
9393
"@types/debounce": "^1.2.1",
94+
"@types/ejs": "^3.1.5",
9495
"@types/mapbox-gl": "^2.7.5",
9596
"@typescript-eslint/eslint-plugin": "^5.37.0",
9697
"@typescript-eslint/parser": "^5.37.0",
@@ -105,6 +106,7 @@
105106
"eslint-plugin-jest": "^27.0.1",
106107
"expo": "^47.0.0",
107108
"expo-module-scripts": "^3.0.4",
109+
"gray-matter": "^4.0.2",
108110
"husky": "^8.0.1",
109111
"jest": "29.7.0",
110112
"jest-cli": "29.7.0",
@@ -115,17 +117,21 @@
115117
"prettier": "2.7.1",
116118
"react": "18.2.0",
117119
"react-docgen": "rnmapbox/react-docgen#rnmapbox-dist-react-docgen-v6",
118-
"react-native": "0.73.0-rc.4",
120+
"react-native": "0.74.2",
119121
"react-native-builder-bob": "^0.23.1",
120122
"react-test-renderer": "18.2.0",
121123
"ts-node": "10.9.1",
122-
"typescript": "5.1.3",
123-
"@mdx-js/mdx": "^3.0.0"
124+
"typescript": "5.1.3"
124125
},
125126
"codegenConfig": {
126127
"name": "rnmapbox_maps_specs",
127128
"type": "all",
128129
"jsSrcsDir": "src/specs",
130+
"includesGeneratedCode": true,
131+
"outputDir": {
132+
"android": "android/src/main/codegen",
133+
"ios": "ios/codegen"
134+
},
129135
"android": {
130136
"javaPackageName": "com.rnmapbox.rnmbx"
131137
}

ios/RNMBX/RNMBXLocationComponentView.h renamed to scripts/rnmbxcodegen/component/ios/component-view.h.ejs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/***
2+
to: ios/rnmbx/generated/<%= Name %>ComponentView.h
3+
***/
14
#ifdef RCT_NEW_ARCH_ENABLED
25

36
#import <UIKit/UIKit.h>
@@ -7,8 +10,7 @@
710

811
NS_ASSUME_NONNULL_BEGIN
912

10-
11-
@interface RNMBXLocationComponentView : RCTViewComponentView
13+
@interface <%= Name %>ComponentView : RCTViewComponentView
1214

1315
@end
1416

ios/RNMBX/RNMBXLocationComponentView.mm renamed to scripts/rnmbxcodegen/component/ios/component-view.mm.ejs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
/***
2+
to: ios/rnmbx/generated/<%= Name %>ComponentView.mm
3+
***/
14
#ifdef RCT_NEW_ARCH_ENABLED
25

3-
#import "RNMBXLocationComponentView.h"
6+
#import "<%= Name %>ComponentView.h"
47

58
#import <React/RCTConversions.h>
69
#import <React/RCTFabricComponentsPlugins.h>
@@ -17,16 +20,16 @@
1720
using namespace facebook::react;
1821

1922

20-
@implementation RNMBXLocationComponentView {
21-
RNMBXLocation *_view;
23+
@implementation <%= Name %>ComponentView {
24+
<%= Name %> *_view;
2225
}
2326

2427
- (instancetype)initWithFrame:(CGRect)frame
2528
{
2629
if (self = [super initWithFrame:frame]) {
27-
static const auto defaultProps = std::make_shared<const RNMBXViewportProps>();
30+
static const auto defaultProps = std::make_shared<const <%= Name %>Props>();
2831
_props = defaultProps;
29-
_view = [[RNMBXLocation alloc] init];
32+
_view = [[<%= Name %> alloc] init];
3033
[self prepareView];
3134

3235
self.contentView = _view;
@@ -45,7 +48,7 @@ - (void)prepareView
4548
if (strongSelf != nullptr && strongSelf->_eventEmitter != nullptr) {
4649
auto type = std::string([[event objectForKey:@"type"] UTF8String]);
4750
auto payload = convertIdToFollyDynamic([event objectForKey:@"payload"]);
48-
RNMBXLocationEventEmitter::OnStatusChanged event = {type, payload};
51+
<%= Name %>EventEmitter::OnStatusChanged event = {type, payload};
4952
strongSelf->_eventEmitter->onStatusChanged(event);
5053
}
5154
}];
@@ -56,13 +59,13 @@ - (void)prepareView
5659

5760
+ (ComponentDescriptorProvider)componentDescriptorProvider
5861
{
59-
return concreteComponentDescriptorProvider<RNMBXViewportComponentDescriptor>();
62+
return concreteComponentDescriptorProvider<<%= Name %>ComponentDescriptor>();
6063
}
6164

6265
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
6366
{
64-
const auto &oldViewProps = static_cast<const RNMBXLocationProps &>(*oldProps);
65-
const auto &newViewProps = static_cast<const RNMBXLocationProps &>(*props);
67+
const auto &oldViewProps = static_cast<const <%= Name %>Props &>(*oldProps);
68+
const auto &newViewProps = static_cast<const <%= Name %>Props &>(*props);
6669

6770
if (!oldProps.get() || oldViewProps.transitionsToIdleUponUserInteraction != newViewProps.transitionsToIdleUponUserInteraction) {
6871
_view.transitionsToIdleUponUserInteraction = convertDynamicToOptional_boolean(newViewProps.transitionsToIdleUponUserInteraction, @"transitionsToIdleUponUserInteraction");
@@ -76,9 +79,9 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
7679
}
7780
@end
7881

79-
Class<RCTComponentViewProtocol> RNMBXViewportCls(void)
82+
Class<RCTComponentViewProtocol> <%= Name %>Cls(void)
8083
{
81-
return RNMBXLocationComponentView.class;
84+
return <%= Name %>ComponentView.class;
8285
}
8386

8487
#endif // RCT_NEW_ARCH_ENABLED
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/***
2+
to: ios/rnmbx/<%= Name %>.swift
3+
userEditable: true
4+
***/
5+
6+
@objc(<%= Name %>)
7+
open class <%= Name %> : RNMBXMapComponentBase {
8+
9+
<% module.spec.properties.forEach(function (property) { %>
10+
@objc
11+
public static func <%= property.name %>(_ view: <%= ComponentName %>, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
12+
// TODO implement
13+
}
14+
<% }) %>
15+
}

ios/RNMBX/RNMBXLocationComponentModule.h renamed to scripts/rnmbxcodegen/componentmodule/ios/module.h.ejs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/***
2+
to: ios/RNMBX/generated/<%= Name %>.h
3+
***/
14
#import <Foundation/Foundation.h>
25
#import <UIKit/UIKit.h>
36

@@ -7,9 +10,9 @@
710
#import <React/RCTBridge.h>
811
#endif
912

10-
@interface RNMBXLocationComponentModule : NSObject
13+
@interface <%= Name %> : NSObject
1114
#ifdef RCT_NEW_ARCH_ENABLED
12-
<NativeRNMBXLocationModuleSpec>
15+
<Native<%= Name %>ModuleSpec>
1316
#else
1417
<RCTBridgeModule>
1518
#endif
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
/***
2+
to: ios/RNMBX/generated/<%= Name %>.mm
3+
***/
14
#import <React/RCTBridge.h>
25
#import <React/RCTUIManager.h>
36
#import <React/RCTUIManagerUtils.h>
47

5-
#import "RNMBXLocationComponentModule.h"
8+
#import "<%= Name %>.h"
9+
10+
#import "<%= ComponentName %>ComponentView.h"
611
#ifdef RCT_NEW_ARCH_ENABLED
7-
#import "RNMBXLocationComponentView.h"
12+
#import "<%= ComponentName %>ComponentView.h"
813
#endif // RCT_NEW_ARCH_ENABLED
914

1015
#import "rnmapbox_maps-Swift.pre.h"
1116

12-
@class RNMBXLocation;
13-
14-
@implementation RNMBXLocationComponentModule
17+
@implementation <%= Name %>
1518

1619
RCT_EXPORT_MODULE();
1720

@@ -32,39 +35,39 @@ - (dispatch_queue_t)methodQueue
3235
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
3336
(const facebook::react::ObjCTurboModule::InitParams &)params
3437
{
35-
return std::make_shared<facebook::react::NativeRNMBXLocationModuleSpecJSI>(params);
38+
return std::make_shared<facebook::react::Native<%= Name %>ModuleSpecJSI>(params);
3639
}
3740
#endif // RCT_NEW_ARCH_ENABLED
3841

39-
- (void)withLocation:(nonnull NSNumber*)viewRef block:(void (^)(RNMBXLocation *))block reject:(RCTPromiseRejectBlock)reject methodName:(NSString *)methodName
42+
- (void)with<%= Name %>:(nonnull NSNumber*)viewRef block:(void (^)(<%= ComponentName %> *))block reject:(RCTPromiseRejectBlock)reject methodName:(NSString *)methodName
4043
{
4144
#ifdef RCT_NEW_ARCH_ENABLED
4245
[self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *viewRegistry) {
43-
RNMBXLocationComponentView *componentView = [self.viewRegistry_DEPRECATED viewForReactTag:viewRef];
44-
RNMBXLocation *view = componentView.contentView;
46+
<%= ComponentName %>ComponentView *componentView = [self.viewRegistry_DEPRECATED viewForReactTag:viewRef];
47+
<%= ComponentName %> *view = componentView.contentView;
4548

4649
#else
4750
[self.bridge.uiManager
4851
addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
49-
RNMBXLocation *view = [uiManager viewForReactTag:viewRef];
52+
<%= ComponentName %> *view = [uiManager viewForReactTag:viewRef];
5053
#endif // RCT_NEW_ARCH_ENABLED
5154
if (view != nil) {
52-
block(view);
55+
block(view);
5356
} else {
5457
reject(methodName, [NSString stringWithFormat:@"Unknown reactTag: %@", viewRef], nil);
5558
}
5659
}];
5760
}
5861

59-
#if false
60-
RCT_EXPORT_METHOD(someMethod:(nonnull NSNumber *)viewRef
62+
<% module.spec.properties.forEach(function (property) { %>
63+
RCT_EXPORT_METHOD(<%= property.name %>:(nonnull NSNumber *)viewRef
6164
resolve:(RCTPromiseResolveBlock)resolve
6265
reject:(RCTPromiseRejectBlock)reject)
6366
{
64-
[self withLocation:viewRef block:^(RNMBXCamera *view) {
65-
[RNMBXLocationManager someMethod:view resolve:resolve reject:reject];
66-
} reject:reject methodName:@"someMethod"];
67+
[self with<%= Name %>:viewRef block:^(<%= ComponentName %> *view) {
68+
[<%= ComponentName %> <%= property.name %>:view resolve:resolve reject:reject];
69+
} reject:reject methodName:@"<%= property.name %>"];
6770
}
68-
#endif
71+
<% }) %>
6972

7073
@end

0 commit comments

Comments
 (0)