Skip to content

Commit

Permalink
fix: 🎨 redefine of namespace StepCounter
Browse files Browse the repository at this point in the history
@dongminyu/react-native-step-counter
react-native-step-counter
RNStepCounter
StepCounter
  • Loading branch information
AndrewDongminYoo committed Aug 19, 2023
1 parent 31aa2c8 commit b8931ea
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 54 deletions.
6 changes: 3 additions & 3 deletions ios/RNStepCounter.h → ios/StepCounter.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifdef RCT_NEW_ARCH_ENABLED
#import <RNStepCounterSpec/RNStepCounterSpec.h>
#import "RNStepCounterSpec.h"

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

@interface RNStepCounter : RCTEventEmitter<RCTBridgeModule>
@interface StepCounter : RCTEventEmitter<RCTBridgeModule>
#endif

@end
6 changes: 3 additions & 3 deletions ios/RNStepCounter.mm → ios/StepCounter.mm
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#import <CoreMotion/CoreMotion.h>
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import "RNStepCounter.h"
#import "StepCounter.h"
#import "SOMotionDetecter.h"

@interface RNStepCounter ()
@interface StepCounter ()
@property (nonatomic, readonly) CMPedometer *pedometer;
@end

@implementation RNStepCounter
@implementation StepCounter
+ (BOOL)requiresMainQueueSetup {
return YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
B2217B4329B5901C00F454BC /* SOMotionDetecter.m in Sources */ = {isa = PBXBuildFile; fileRef = B2217B3F29B5901C00F454BC /* SOMotionDetecter.m */; };
B2217B4A29B5AAFB00F454BC /* RNStepCounter.m in Sources */ = {isa = PBXBuildFile; fileRef = B2217B4929B5AAFB00F454BC /* RNStepCounter.m */; };
B2217B4A29B5AAFB00F454BC /* StepCounter.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2217B4929B5AAFB00F454BC /* StepCounter.mm */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -27,8 +27,8 @@
134814201AA4EA6300B7C361 /* libStepCounter.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libStepCounter.a; path = libRNStepCounter.a; sourceTree = BUILT_PRODUCTS_DIR; };
B2217B3F29B5901C00F454BC /* SOMotionDetecter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SOMotionDetecter.m; sourceTree = "<group>"; };
B2217B4029B5901C00F454BC /* SOMotionDetecter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SOMotionDetecter.h; sourceTree = "<group>"; };
B2217B4929B5AAFB00F454BC /* RNStepCounter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNStepCounter.m; sourceTree = "<group>"; };
B3E7B5881CC2AC0600A0062D /* RNStepCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNStepCounter.h; sourceTree = "<group>"; };
B2217B4929B5AAFB00F454BC /* StepCounter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StepCounter.mm; sourceTree = "<group>"; };
B3E7B5881CC2AC0600A0062D /* StepCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StepCounter.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -55,18 +55,18 @@
children = (
B2217B4029B5901C00F454BC /* SOMotionDetecter.h */,
B2217B3F29B5901C00F454BC /* SOMotionDetecter.m */,
B3E7B5881CC2AC0600A0062D /* RNStepCounter.h */,
B2217B4929B5AAFB00F454BC /* RNStepCounter.m */,
B3E7B5881CC2AC0600A0062D /* StepCounter.h */,
B2217B4929B5AAFB00F454BC /* StepCounter.mm */,
134814211AA4EA7D00B7C361 /* Products */,
);
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
58B511DA1A9E6C8500147676 /* RNStepCounter */ = {
58B511DA1A9E6C8500147676 /* StepCounter */ = {
isa = PBXNativeTarget;
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNStepCounter" */;
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "StepCounter" */;
buildPhases = (
58B511D71A9E6C8500147676 /* Sources */,
58B511D81A9E6C8500147676 /* Frameworks */,
Expand All @@ -76,7 +76,7 @@
);
dependencies = (
);
name = RNStepCounter;
name = StepCounter;
productName = RCTDataManager;
productReference = 134814201AA4EA6300B7C361 /* libStepCounter.a */;
productType = "com.apple.product-type.library.static";
Expand All @@ -95,7 +95,7 @@
};
};
};
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNStepCounter" */;
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "StepCounter" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
Expand All @@ -108,7 +108,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
58B511DA1A9E6C8500147676 /* RNStepCounter */,
58B511DA1A9E6C8500147676 /* StepCounter */,
);
};
/* End PBXProject section */
Expand All @@ -118,7 +118,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B2217B4A29B5AAFB00F454BC /* RNStepCounter.m in Sources */,
B2217B4A29B5AAFB00F454BC /* StepCounter.mm in Sources */,
B2217B4329B5901C00F454BC /* SOMotionDetecter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -169,7 +169,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -212,7 +212,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand All @@ -230,7 +230,7 @@
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = RNStepCounter;
PRODUCT_NAME = StepCounter;
SKIP_INSTALL = YES;
};
name = Debug;
Expand All @@ -246,15 +246,15 @@
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = RNStepCounter;
PRODUCT_NAME = StepCounter;
SKIP_INSTALL = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNStepCounter" */ = {
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "StepCounter" */ = {
isa = XCConfigurationList;
buildConfigurations = (
58B511ED1A9E6C8500147676 /* Debug */,
Expand All @@ -263,7 +263,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNStepCounter" */ = {
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "StepCounter" */ = {
isa = XCConfigurationList;
buildConfigurations = (
58B511F01A9E6C8500147676 /* Debug */,
Expand Down
12 changes: 9 additions & 3 deletions RNStepCounter.podspec → react-native-step-counter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
s.name = "RNStepCounter"
s.name = "react-native-step-counter"
s.version = package["version"]
s.summary = package["summary"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]
s.description = package["description"]

s.platforms = { :ios => "11.0" }
s.source = { :git => "https://github.com/AndrewDongminYoo/react-native-step-counter.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,swift}"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
install_modules_dependencies(s)
else
s.dependency "React-Core"

# Don't install the dependencies when we run `pod install` in the old architecture.
Expand All @@ -31,5 +36,6 @@ Pod::Spec.new do |s|
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
end
30 changes: 14 additions & 16 deletions src/NativeStepCounter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
import TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

/**
* `StepCountData` is an object with four properties: `distance`, `steps`, `startDate`, and `endDate`.
*
* @typedef StepCountData object - The Object that contains the step count data.
* @property {string} counterType - The type of counter used to count the steps.
* @property {number} steps - The number of steps taken during the time period.
* @property {number} startDate - The start date of the data.
* @property {number} endDate - The end date of the data.
* @property {number} distance - The distance in meters that the user has walked or run.
* @property {number|undefined} floorsAscended - number of floors ascended (iOS only)
* @property {number|undefined} floorsDescended - number of floors descended (iOS only)
* StepCountData object - The Object that contains the step count data.
* counterType - The type of counter used to count the steps.
* steps - The number of steps taken during the time period.
* startDate - The start date of the data.
* endDate - The end date of the data.
* distance - The distance in meters that the user has walked or run.
* floorsAscended - number of floors ascended (iOS only)
* floorsDescended - number of floors descended (iOS only)
*/
export type StepCountData = {
counterType: string; // 'STEP_COUNTER'|'ACCELEROMETER'|'CMPedometer'
Expand All @@ -29,14 +28,13 @@ export const eventName = 'StepCounter.stepCounterUpdate';

export interface Spec extends TurboModule {
/**
* Check if the step counter is supported on the device.
*
* @description Check if the step counter is supported on the device.
* @async
* @returns {Promise<Record<string, boolean>>} Returns the `Promise` object,
* including information such as whether the user's device has a step counter sensor by default (`supported`)
* and whether the user has allowed the app to measure the pedometer data. (`granted`)
* @property {boolean} granted - The permission is granted or not.
* @property {boolean} supported - The step counter is supported or not.
* granted - The permission is granted or not.
* supported - The step counter is supported or not.
* @example
* isStepCountingSupported().then((response) => {
* const { granted, supported } = response;
Expand All @@ -61,4 +59,4 @@ export interface Spec extends TurboModule {
}

/* Getting enforcing the module from the registry. */
export default TurboModuleRegistry.getEnforcing<Spec>('RNStepCounter') as Spec;
export default TurboModuleRegistry.getEnforcing<Spec>('StepCounter') as Spec;
17 changes: 5 additions & 12 deletions src/index.ts → src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export interface ParsedStepCountData {
* In such a case, we shouldn't de-alloc TurboModuleManager if there
* aren't any strong references to it in ObjC. Hence, we give
* __turboModuleProxy a strong reference to TurboModuleManager.
*
* @see https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/TurboModule/TurboModuleRegistry.js
* @see https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/RCTTurboModuleManager.mm
* @see https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp
Expand All @@ -48,10 +47,9 @@ const StepCounterModule = isTurboModuleEnabled ? require('./NativeStepCounter').
/**
* A module that allows you to get the step count data.
* `CMStepCounter` is deprecated in iOS 8.0. Used `CMPedometer` instead.
*
* @property {number} floorsAscended - The number of floors ascended during the time period. iOS Only.
* @property {number} floorsDescended - The number of floors descended during the time period. iOS Only.
* @property {string} counterType - The type of counter used to count the steps.
* floorsAscended - The number of floors ascended during the time period. iOS Only.
* floorsDescended - The number of floors descended during the time period. iOS Only.
* counterType - The type of counter used to count the steps.
* @throws {Error} LINKING_ERROR - Throws Error If global variable turboModuleProxy is undefined.
* @example
* import { RNStepCounter } from '@dongminyu/react-native-step-counter';
Expand All @@ -76,7 +74,6 @@ export const isSensorWorking = StepEventEmitter.listenerCount(eventName) > 0;
/**
* Transform the step count data into a more readable format.
* You can use it or directly use the `StepCountData` type.
*
* @param {StepCountData} data - Step Counter Sensor Event Data.
* @returns {ParsedStepCountData} - String Parsed Count Data.
*/
Expand All @@ -102,7 +99,6 @@ export function parseStepData(data: StepCountData): ParsedStepCountData {

/**
* If you're using a method or property that's not available on the current platform, throw this error.
*
* @param {string} moduleName The name of the module.
* @param {string} propertyName The name of the property.
* @returns {Error} The error.
Expand All @@ -125,12 +121,11 @@ class UnavailabilityError extends Error {
/**
* Returns whether the stepCounter is enabled on the device.
* iOS 8.0+ only. Android is available since KitKat (4.4 / API 19).
*
* @see https://developer.android.com/about/versions/android-4.4.html
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613963-isstepcountingavailable
* @returns {Promise<Record<string, boolean>>} A promise that resolves with an object containing the stepCounter availability.
* @property {boolean} supported - Whether the stepCounter is supported on device.
* @property {boolean} granted - Whether user granted the permission.
* supported - Whether the stepCounter is supported on device.
* granted - Whether user granted the permission.
*/
export function isStepCountingSupported(): Promise<Record<string, boolean>> {
return RNStepCounter.isStepCountingSupported();
Expand All @@ -142,7 +137,6 @@ export function isStepCountingSupported(): Promise<Record<string, boolean>> {
* Specifying a start date that is more than seven days in the past returns only the available data.
* ### iOS
* `CMStepCounter.startStepCountingUpdates` is deprecated since iOS 8.0. so used `CMPedometer.startUpdates` instead.
*
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613950-startupdates
* @see https://developer.apple.com/documentation/coremotion/cmstepcounter/1616151-startstepcountingupdates
* @param {Date} start A date indicating the start of the range over which to measure steps.
Expand All @@ -168,7 +162,6 @@ export function startStepCounterUpdate(start: Date, callBack: StepCountUpdateCal
* Stop the step counter updates.
* ### iOS
* `CMStepCounter.stopStepCountingUpdates` is deprecated since iOS 8.0. so used `CMPedometer.stopUpdates` instead.
*
* @see https://developer.apple.com/documentation/coremotion/cmpedometer/1613973-stopupdates
* @see https://developer.apple.com/documentation/coremotion/cmstepcounter/1616157-stopstepcountingupdates
*/
Expand Down

0 comments on commit b8931ea

Please sign in to comment.