Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/move-reject-promise-to-core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@infinitered/react-native-mlkit-core": minor
"@infinitered/react-native-mlkit-face-detection": patch
"@infinitered/react-native-mlkit-object-detection": patch
"@infinitered/react-native-mlkit-image-labeling": patch
---

Move the `rejectPromiseWithMessage` Swift helper into RNMLKit core so it can be shared across modules instead of being duplicated in each one.
17 changes: 17 additions & 0 deletions modules/react-native-mlkit-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ var image:InputImage = RNMLKitImage(imagePath, appContext.reactContext!!).image
ImagePickerAsset.
- `appContext` is the AppContext from your expo module -- it's accessible as a property on the Module class.

### rejectPromiseWithMessage

#### Swift

A shared helper for rejecting an Expo `Promise` with a consistent `NSError` shape. Use it from any RNMLKit module to
surface errors back to JavaScript.

```swift
import RNMLKitCore

rejectPromiseWithMessage(promise: promise, message: "Something went wrong", domain: ERROR_DOMAIN)
```

- `promise` is the Expo `Promise` to reject.
- `message` is the localized description attached to the error.
- `domain` is the error domain (e.g. a module-specific error domain constant).

### React Components

#### BoundingBoxView
Expand Down
11 changes: 11 additions & 0 deletions modules/react-native-mlkit-core/ios/RNMLKitPromise.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ExpoModulesCore

/// Rejects a promise with a specified message and domain.
///
/// Shared helper used across the React Native MLKit modules to surface
/// errors back to JavaScript with a consistent `NSError` shape.
public func rejectPromiseWithMessage(promise: Promise, message: String, domain: String) {
promise.reject(
NSError(domain: domain, code: 1, userInfo: [NSLocalizedDescriptionKey: message])
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import ExpoModulesCore
import MLKitFaceDetection
import RNMLKitCore

// Function to reject a promise with a specified message and domain
func rejectPromiseWithMessage(promise: Promise, message: String, domain: String) {
promise.reject(
NSError(domain: domain, code: 1, userInfo: [NSLocalizedDescriptionKey: message])
)
}

let ERROR_DOMAIN: String = "red.infinite.reactnativemlkit.FaceDetectorErrorDomain"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ExpoModulesCore
import MLKitCommon
import MLKitImageLabelingCustom
import MLKitVision
import RNMLKitCore

// Structure to represent the result of image labeling
struct RNMLKitImageLabelResult: Record {
Expand All @@ -23,13 +24,6 @@ struct RNMLKitImageLabelerOptionsRecord: Record {
var maxResultCount: Int = 10
}

// Function to reject a promise with a specified message and domain
func rejectPromiseWithMessage(promise: Promise, message: String, domain: String) {
promise.reject(
NSError(domain: domain, code: 1, userInfo: [NSLocalizedDescriptionKey: message])
)
}

struct RNMLKitImageLabelerSpec: Record {
@Field
var modelName: String = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import ExpoModulesCore

// Function to reject a promise with a specified message and domain
func rejectPromiseWithMessage(promise: Promise, message: String, domain: String) {
promise.reject(
NSError(domain: domain, code: 1, userInfo: [NSLocalizedDescriptionKey: message])
)
}
import RNMLKitCore

public struct RNMLKitObjectDetectionModelSpec: Record {
public init() {}
Expand Down
Loading