Skip to content

Commit 58037cd

Browse files
authored
(WIP): Adds web partitions to throw error for unsupported platforms (#205)
* Updated FaceDetection for web errors * HomeScreen testing * Updates face-detection module * Updates image-labeling module * Updates object-detection module * Add partitions for image labeling for web * Adds partitions for ObjectDetection Module and has the error displaying as desired on Test App * Image Labeling Web Error throwing as expected * Switch to using UnavailabilityError * Updated faceDetectionContext * docs(changeset): Adds web partitions to throw error on function calls * Update documentation to reflect changes
1 parent 3b07ad6 commit 58037cd

38 files changed

+299
-41
lines changed

.changeset/smart-carrots-do.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@infinitered/react-native-mlkit-document-scanner": minor
3+
"@infinitered/react-native-mlkit-object-detection": minor
4+
"@infinitered/react-native-mlkit-face-detection": minor
5+
"@infinitered/react-native-mlkit-image-labeling": minor
6+
"@infinitered/react-native-mlkit-core": minor
7+
"@infinitered/react-native-mlkit-docs": minor
8+
"@infinitered/tsconfig": minor
9+
"example-app": minor
10+
---
11+
12+
Adds web partitions to throw error on function calls

apps/ExampleApp/app/screens/HomeScreen/HomeScreen.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const HomeScreen: FC<HomeScreenProps> = observer(function HomeScreen() {
2828
)
2929

3030
return (
31-
<Screen style={$root} preset="fixed">
31+
<Screen style={$root} preset="auto">
3232
<View style={$shadowSpace}>
3333
<View style={$titleContainer}>
3434
<Text preset={"heading"} text={"Infinite Red AI"} />
@@ -60,6 +60,8 @@ const $listContainer: ViewStyle = {
6060
position: "relative",
6161
top: -32,
6262
marginTop: 16,
63+
flex: 1,
64+
display: "flex",
6365
}
6466

6567
const $contentContainerStyle: ViewStyle = { paddingBottom: 100, paddingTop: 24 }

docs/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ need.
4545
Logic and classes shared by all the types have been extracted into `react-native-mlkit-core`, to reduce code
4646
duplication.
4747

48+
### Is RN MLKit compatible with all platforms?
49+
50+
While we aim to support all platforms, we currently only support iOS and Android. The native modules do not work on the
51+
web, and we do not have plans to support the web at this time.
52+
4853
---

docs/running-the-example-app/android.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ title: Android
77

88
An example app is provided that demonstrates the correct use of the modules in a react-native app.
99

10+
:::note
11+
MLKit is not supported in the Android emulator. You will need to use a hardware device.
12+
:::
13+
1014
## 1. Clone the project
1115

1216
```bash

docs/running-the-example-app/ios.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ This is a [known issue](https://issuetracker.google.com/issues/178965151?pli=1)
1515
waiting either for a fix from Google, or for Apple to release a native `arm64` simulator.
1616
:::
1717

18+
:::note
19+
MLKit is not supported in the iOS simulator. You will need to use a hardware device.
20+
:::
21+
1822
## 1. Clone the project
1923

2024
```bash
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const WEB_ERROR = "react-native-mlkit is not supported on web";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const WEB_ERROR = "react-native-mlkit is not supported on web";
2+
export const RNMLKIT_MODULE_NAME = "react-native-mlkit-face-detection";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { PropsWithChildren } from "react";
2+
3+
import { RNMLKitFaceDetectorOptions } from "../types";
4+
5+
interface Props extends PropsWithChildren {
6+
options?: RNMLKitFaceDetectorOptions;
7+
deferInitialization?: boolean;
8+
}
9+
10+
export const FaceDetectionProvider = ({ children }: Props) => children;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { UnavailabilityError } from "expo-modules-core";
2+
3+
import { WEB_ERROR, RNMLKIT_MODULE_NAME } from "../constants";
4+
5+
const useFaceDetection = () => ({
6+
detectFaces: () => {
7+
throw new UnavailabilityError(RNMLKIT_MODULE_NAME, WEB_ERROR);
8+
},
9+
error: null,
10+
initialize: () => {
11+
throw new Error(WEB_ERROR);
12+
},
13+
status: "ready",
14+
});
15+
16+
export default useFaceDetection;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { UnavailabilityError } from "expo-modules-core";
2+
3+
import { UseFaceDetectionReturnType } from "./useFacesInPhoto";
4+
import { RNMLKIT_MODULE_NAME, WEB_ERROR } from "../constants";
5+
6+
export function useFacesInPhoto(imageUri?: string): UseFaceDetectionReturnType {
7+
return {
8+
clearFaces: () => {
9+
throw new UnavailabilityError(RNMLKIT_MODULE_NAME, WEB_ERROR);
10+
},
11+
error: WEB_ERROR,
12+
status: "ready",
13+
faces: [],
14+
} as UseFaceDetectionReturnType;
15+
}

0 commit comments

Comments
 (0)