Skip to content

Commit

Permalink
perf(iOS): ⬆️ all .m files in StepCounter folder should be renamed to…
Browse files Browse the repository at this point in the history
… .mm

React Native’s architecture can include both .h
and .mm files. According to the React Native
documentation, all .m files within the AppName
inner folder should be renamed from .m to .mm.
Objective-C++ is an extension of Objective-C
that allows you to use C++ code within an
Objective-C program.

[BLOCKING] cannot build iOS application #1
  • Loading branch information
AndrewDongminYoo committed Mar 13, 2023
1 parent 09a3056 commit 983be85
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .yarnclean
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ example/android/app/build
example/ios/build
example/ios/DerivedData

# unsupport platform
# unsupported platform
web
linux
windows
Expand All @@ -32,7 +32,6 @@ coverage

# configs
.gitattributes
.flowconfig
.yarn-metadata.json
.yarn-error.log
.package-lock.json
Expand Down
6 changes: 3 additions & 3 deletions example/ios/StepCounterExampleTests/StepCounterExampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test
if (test(view)) {
return YES;
}
for (UIView *subview in [view subviews]) {
for (UIView *subview in view.subviews) {
if ([self findSubviewInView:subview matching:test]) {
return YES;
}
Expand All @@ -28,7 +28,7 @@ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test

- (void)testRendersWelcomeScreen
{
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
UIViewController *vc = RCTSharedApplication().delegate.window.rootViewController;
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;

Expand All @@ -42,7 +42,7 @@ - (void)testRendersWelcomeScreen
});
#endif

while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
while (date.timeIntervalSinceNow > 0 && !foundElement && !redboxError) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];

Expand Down
5 changes: 3 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
"build-android": "react-native build-android --mode=Release",
"prepods": "react-native setup-ios-permissions",
"ios": "react-native run-ios --scheme StepCounterExample",
"run-ios": "yarn ios --configuration Debug",
"build-ios": "yarn ios --configuration Release",
"run-ios": "yarn ios --mode Debug",
"build-ios": "yarn ios --mode Release",
"clear": "react-native clean --include watchman,yarn,metro,android",
"doctor": "react-native doctor --fix",
"pods": "(cd ios && pod install --no-repo-update)",
"start": "react-native start --reset-cache",
"watch": "tsc --noEmit --watch"
},
"dependencies": {
"@dongminyu/react-native-step-counter": "../",
"react": "18.2.0",
"react-native": "0.71.4",
"react-native-permissions": "^3.7.3"
Expand Down
3 changes: 3 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,9 @@
"@babel/helper-validator-identifier" "^7.19.1"
to-fast-properties "^2.0.0"

"@dongminyu/react-native-step-counter@../":
version "0.1.9"

"@hapi/hoek@^9.0.0":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
Expand Down
6 changes: 6 additions & 0 deletions ios/RNStepCounter.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#ifdef RCT_NEW_ARCH_ENABLED
#import "RNStepCounterSpec.h"

@interface RNStepCounter : NSObject <NativeStepCounterSpec>
#else
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import "SOMotionDetecter.h"

@interface RNStepCounter : RCTEventEmitter<RCTBridgeModule>
#endif

@end
9 changes: 9 additions & 0 deletions ios/RNStepCounter.m → ios/RNStepCounter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,13 @@ - (instancetype)init {
return self;
}

// Don't compile this code when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeStepCounterSpecJSI>(params);
}
#endif

@end
File renamed without changes.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@
"codegenConfig": {
"name": "RNStepCounterSpec",
"type": "modules",
"jsSrcsDir": "src"
"jsSrcsDir": "src",
"android": {
"javaPackageName": "com.stepcounter"
}
}
}
4 changes: 2 additions & 2 deletions src/NativeStepCounter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TurboModule } from 'react-native';
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
import { TurboModuleRegistry } from 'react-native';

export type StepCountData = {
Expand Down Expand Up @@ -50,4 +50,4 @@ export interface Spec extends TurboModule {
}

/* Getting enforcing the module from the registry. */
export default TurboModuleRegistry.getEnforcing<Spec>('RNStepCounter') as Spec;
export default TurboModuleRegistry.get<Spec>('RNStepCounter') as Spec | null;
3 changes: 0 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@dongminyu/react-native-step-counter": ["./src/index"]
},
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
Expand Down

0 comments on commit 983be85

Please sign in to comment.