Skip to content

Commit ec7b41f

Browse files
javachemeta-codesync[bot]
authored andcommitted
Sync RCTNativeSampleTurboModuleSpec (#54918)
Summary: Pull Request resolved: #54918 This is a checked-in copy of codegen (not sure why) which is out-of-date and prevents me from investigating the backwards-compat regression in D89373357 Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D89373356 fbshipit-source-id: 05433bca43120656710a15460b61d6cb64a57aad
1 parent ca2fc14 commit ec7b41f

5 files changed

Lines changed: 190 additions & 93 deletions

File tree

packages/react-native/ReactCommon/react/nativemodule/samples/ReactCommon-Samples.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Pod::Spec.new do |s|
5353
s.dependency "React-Core"
5454
s.dependency "React-cxxreact"
5555
s.dependency "React-jsi"
56+
s.dependency "RCTTypeSafety"
5657
add_dependency(s, "React-RCTFBReactNativeSpec")
5758
add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"])
5859
add_dependency(s, "React-NativeModulesApple")

packages/react-native/ReactCommon/react/nativemodule/samples/platform/android/NativeSampleTurboModuleSpec.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package com.facebook.fbreact.specs;
1111

12+
import com.facebook.proguard.annotations.DoNotStrip;
1213
import com.facebook.react.bridge.Callback;
1314
import com.facebook.react.bridge.Promise;
1415
import com.facebook.react.bridge.ReactApplicationContext;
@@ -52,13 +53,14 @@ protected final void emitOnChange(ReadableMap value) {
5253
mEventEmitterCallback.invoke("onChange", value);
5354
}
5455

55-
protected void emitOnSubmit(ReadableArray value) {
56+
protected final void emitOnSubmit(ReadableArray value) {
5657
mEventEmitterCallback.invoke("onSubmit", value);
5758
}
5859

5960
protected abstract Map<String, Object> getTypedExportedConstants();
6061

6162
@Override
63+
@DoNotStrip
6264
public final @Nullable Map<String, Object> getConstants() {
6365
Map<String, Object> constants = getTypedExportedConstants();
6466
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
@@ -70,78 +72,97 @@ protected void emitOnSubmit(ReadableArray value) {
7072
undeclaredConstants.removeAll(optionalFlowConstants);
7173
if (!undeclaredConstants.isEmpty()) {
7274
throw new IllegalStateException(
73-
"Native Module Flow doesn't declare constants: " + undeclaredConstants);
75+
String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
7476
}
7577
undeclaredConstants = obligatoryFlowConstants;
7678
undeclaredConstants.removeAll(constants.keySet());
7779
if (!undeclaredConstants.isEmpty()) {
7880
throw new IllegalStateException(
79-
"Native Module doesn't fill in constants: " + undeclaredConstants);
81+
String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
8082
}
8183
}
8284
return constants;
8385
}
8486

8587
@ReactMethod
88+
@DoNotStrip
8689
public abstract void voidFunc();
8790

8891
@ReactMethod(isBlockingSynchronousMethod = true)
92+
@DoNotStrip
8993
public abstract boolean getBool(boolean arg);
9094

9195
@ReactMethod(isBlockingSynchronousMethod = true)
96+
@DoNotStrip
9297
public double getEnum(double arg) {
9398
return 0;
9499
}
95100

96101
@ReactMethod(isBlockingSynchronousMethod = true)
102+
@DoNotStrip
97103
public abstract double getNumber(double arg);
98104

99105
@ReactMethod(isBlockingSynchronousMethod = true)
106+
@DoNotStrip
100107
public abstract String getString(String arg);
101108

102109
@ReactMethod(isBlockingSynchronousMethod = true)
110+
@DoNotStrip
103111
public abstract WritableArray getArray(ReadableArray arg);
104112

105113
@ReactMethod(isBlockingSynchronousMethod = true)
114+
@DoNotStrip
106115
public abstract WritableMap getObject(ReadableMap arg);
107116

108117
@ReactMethod(isBlockingSynchronousMethod = true)
118+
@DoNotStrip
109119
public abstract WritableMap getUnsafeObject(ReadableMap arg);
110120

111121
@ReactMethod(isBlockingSynchronousMethod = true)
122+
@DoNotStrip
112123
public abstract double getRootTag(double arg);
113124

114125
@ReactMethod(isBlockingSynchronousMethod = true)
126+
@DoNotStrip
115127
public abstract WritableMap getValue(double x, String y, ReadableMap z);
116128

117129
@ReactMethod
130+
@DoNotStrip
118131
public abstract void getValueWithCallback(Callback callback);
119132

120133
@ReactMethod
134+
@DoNotStrip
121135
public abstract void getValueWithPromise(boolean error, Promise promise);
122136

123137
@ReactMethod
138+
@DoNotStrip
124139
public void voidFuncThrows() {}
125140

126141
@ReactMethod(isBlockingSynchronousMethod = true)
142+
@DoNotStrip
127143
public WritableMap getObjectThrows(ReadableMap arg) {
128144
return null;
129145
}
130146

131147
@ReactMethod
148+
@DoNotStrip
132149
public void promiseThrows(Promise promise) {}
133150

134151
@ReactMethod
152+
@DoNotStrip
135153
public void voidFuncAssert() {}
136154

137155
@ReactMethod(isBlockingSynchronousMethod = true)
156+
@DoNotStrip
138157
public WritableMap getObjectAssert(ReadableMap arg) {
139158
return null;
140159
}
141160

142161
@ReactMethod
162+
@DoNotStrip
143163
public void promiseAssert(Promise promise) {}
144164

145165
@ReactMethod
166+
@DoNotStrip
146167
public void getImageUrl(Promise promise) {}
147168
}

packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTNativeSampleTurboModuleSpec.h

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,78 @@
99

1010
#import <vector>
1111

12-
#import <Foundation/Foundation.h>
12+
#ifndef __cplusplus
13+
#error This file must be compiled as Obj-C++. If you are importing it, you must change your file extension to .mm.
14+
#endif
1315

16+
#import <Foundation/Foundation.h>
17+
#import <RCTRequired/RCTRequired.h>
18+
#import <RCTTypeSafety/RCTConvertHelpers.h>
19+
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
1420
#import <React/RCTBridgeModule.h>
15-
1621
#import <ReactCommon/RCTTurboModule.h>
1722

1823
NS_ASSUME_NONNULL_BEGIN
1924

20-
/**
21-
* The ObjC protocol based on the JS Flow type for SampleTurboModule.
22-
*/
25+
namespace JS::NativeSampleTurboModule {
26+
struct Constants {
27+
struct Builder {
28+
struct Input {
29+
RCTRequired<bool> const1;
30+
RCTRequired<double> const2;
31+
RCTRequired<NSString *> const3;
32+
};
33+
34+
/** Initialize with a set of values */
35+
Builder(const Input i);
36+
/** Initialize with an existing Constants */
37+
Builder(Constants i);
38+
/** Builds the object. Generally used only by the infrastructure. */
39+
NSDictionary *buildUnsafeRawValue() const
40+
{
41+
return _factory();
42+
};
43+
44+
private:
45+
NSDictionary * (^_factory)(void);
46+
};
47+
48+
static Constants fromUnsafeRawValue(NSDictionary *const v)
49+
{
50+
return {v};
51+
}
52+
NSDictionary *unsafeRawValue() const
53+
{
54+
return _v;
55+
}
56+
57+
private:
58+
Constants(NSDictionary *const v) : _v(v) {}
59+
NSDictionary *_v;
60+
};
61+
62+
} // namespace JS::NativeSampleTurboModule
63+
64+
inline JS::NativeSampleTurboModule::Constants::Builder::Builder(const Input i)
65+
: _factory(^{
66+
NSMutableDictionary *d = [NSMutableDictionary new];
67+
auto const1 = i.const1.get();
68+
d[@"const1"] = @(const1);
69+
auto const2 = i.const2.get();
70+
d[@"const2"] = @(const2);
71+
auto const3 = i.const3.get();
72+
d[@"const3"] = const3;
73+
return d;
74+
})
75+
{
76+
}
77+
inline JS::NativeSampleTurboModule::Constants::Builder::Builder(Constants i)
78+
: _factory(^{
79+
return i.unsafeRawValue();
80+
})
81+
{
82+
}
83+
2384
@protocol NativeSampleTurboModuleSpec <RCTBridgeModule, RCTTurboModule>
2485

2586
- (void)voidFunc;
@@ -40,32 +101,32 @@ NS_ASSUME_NONNULL_BEGIN
40101
- (void)voidFuncAssert;
41102
- (NSDictionary *)getObjectAssert:(NSDictionary *)arg;
42103
- (void)promiseAssert:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
43-
- (NSDictionary *)constantsToExport;
44-
- (NSDictionary *)getConstants;
104+
- (void)getImageUrl:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
105+
- (facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants>)constantsToExport;
106+
- (facebook::react::ModuleConstants<JS::NativeSampleTurboModule::Constants>)getConstants;
45107

46108
@end
47109

48110
@interface NativeSampleTurboModuleSpecBase : NSObject {
49111
@protected
50112
facebook::react::EventEmitterCallback _eventEmitterCallback;
51113
}
52-
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *_Nonnull)eventEmitterCallbackWrapper;
114+
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper;
115+
53116
- (void)emitOnPress;
54-
- (void)emitOnClick:(NSString *)value;
117+
- (void)emitOnClick:(NSString *_Nonnull)value;
55118
- (void)emitOnChange:(NSDictionary *)value;
56-
- (void)emitOnSubmit:(NSArray *)value;
119+
- (void)emitOnSubmit:(NSArray<id<NSObject>> *)value;
57120
@end
58121

59122
namespace facebook::react {
60-
61123
/**
62-
* The iOS TurboModule impl specific to SampleTurboModule.
124+
* ObjC++ class for module 'NativeSampleTurboModule'
63125
*/
64126
class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public ObjCTurboModule {
65127
public:
66128
NativeSampleTurboModuleSpecJSI(const ObjCTurboModule::InitParams &params);
67129
};
68-
69130
} // namespace facebook::react
70131

71132
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)