Skip to content

Commit 3e50e79

Browse files
authored
[MOO-2401]: add mendix-native as dependency (#614)
2 parents efa607c + 6619332 commit 3e50e79

32 files changed

Lines changed: 213 additions & 394 deletions

‎configs/e2e/mendix-versions.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"latest": "11.14.0"
2+
"latest": "11.15.0"
33
}

‎configs/jsactions/rollup.config.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export default async args => {
138138

139139
const nativeExternal = [
140140
/^mendix\//,
141+
/^mendix-native(\/|$)/,
141142
/^react-native(\/|$)/,
142143
/^react-native-windows(\/|$)/,
143144
/^react-native-web(\/|$)/,

‎packages/jsActions/mobile-resources-native/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1616
- Fixed an issue where the `TakePicture` and `TakePictureAdvanced` actions did not properly clean up temporary files.
1717
- Replaced @notifee/react-native with react-native-notify-kit library.
1818

19+
### Added
20+
21+
- We added mendix-native as a dependency to provide native file system.
22+
1923
## [12.1.0] Native Mobile Resources - 2026-6-10
2024

2125
- Updated react-native from version 0.83.4 to 0.84.1.

‎packages/jsActions/mobile-resources-native/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"marketplace": {
1212
"name": "Native Mobile Resources",
1313
"description": "Download this module to access a rich set of widgets and nanoflow actions created for native mobile, including authentication, network, platform, and more. A must-have for native mobile development!",
14-
"minimumMXVersion": "11.12.3",
14+
"minimumMXVersion": "11.15.0",
1515
"marketplaceId": 109513
1616
},
1717
"testProject": {
@@ -34,6 +34,7 @@
3434
"@sbaiahmed1/react-native-biometrics": "0.15.0",
3535
"@swan-io/react-native-browser": "1.0.1",
3636
"fbjs": "3.0.4",
37+
"mendix-native": "https://github.com/mendix/mendix-native/releases/download/v0.6.0/mendix-native-v0.6.0.tgz",
3738
"mime": "3.0.0",
3839
"react-native-blob-util": "0.24.7",
3940
"react-native-device-info": "15.0.2",

‎packages/jsActions/mobile-resources-native/src/camera/TakePicture.ts‎

Lines changed: 10 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
88
import { Big } from "big.js";
9-
import { Alert, Linking, NativeModules, Platform } from "react-native";
9+
import { NativeFileSystem } from "mendix-native";
10+
import { Alert, Linking, Platform } from "react-native";
1011
import {
1112
CameraOptions,
1213
ErrorCode,
@@ -16,7 +17,8 @@ import {
1617
launchImageLibrary
1718
} from "react-native-image-picker";
1819
import { getLocales } from "react-native-localize";
19-
import { ImagePickerV2Options, ImagePickerV2Response, PictureQuality, PictureSource } from "../../typings/Camera";
20+
import RNPermissions from "react-native-permissions";
21+
import { PictureQuality, PictureSource } from "../../typings/Camera";
2022

2123
// BEGIN EXTRA CODE
2224
// END EXTRA CODE
@@ -55,10 +57,6 @@ export async function TakePicture(
5557
);
5658
}
5759

58-
// V3 dropped the feature of providing an action sheet so users can decide on which action to take, camera or library.
59-
const nativeVersionMajor = NativeModules?.ImagePickerManager?.showImagePicker ? 2 : 4;
60-
const RNPermissions = nativeVersionMajor === 4 ? (await import("react-native-permissions")).default : null;
61-
6260
try {
6361
const uri = await takePicture();
6462

@@ -77,32 +75,14 @@ export async function TakePicture(
7775

7876
function takePicture(): Promise<string | undefined> {
7977
return new Promise((resolve, reject) => {
80-
const options = nativeVersionMajor === 2 ? getOptionsV2() : getOptions();
78+
const options = getOptions();
8179
getPictureMethod()
8280
.then(method =>
83-
method(options, (response: ImagePickerV2Response | ImagePickerResponse) => {
81+
method(options, (response: ImagePickerResponse) => {
8482
if (response.didCancel) {
8583
return resolve(undefined);
8684
}
8785

88-
if (nativeVersionMajor === 2) {
89-
const responseV2 = response as ImagePickerV2Response;
90-
91-
if (responseV2.error) {
92-
const unhandledError = handleImagePickerV2Error(responseV2.error);
93-
94-
if (!unhandledError) {
95-
return resolve(undefined);
96-
}
97-
98-
return reject(new Error(responseV2.error));
99-
}
100-
101-
return resolve(responseV2.uri);
102-
}
103-
104-
response = response as ImagePickerResponse;
105-
10686
if (response.errorCode) {
10787
handleImagePickerV4Error(response.errorCode, response.errorMessage);
10888

@@ -118,7 +98,7 @@ export async function TakePicture(
11898

11999
async function safeRemove(filePath: string): Promise<void> {
120100
try {
121-
await NativeModules.MxFileSystem.remove(filePath);
101+
await NativeFileSystem.remove(filePath);
122102
} catch (error) {
123103
console.warn(`Failed to remove file at ${filePath}. Error: ${error}`);
124104
// ignore error
@@ -127,7 +107,7 @@ export async function TakePicture(
127107

128108
function storeFile(imageObject: mendix.lib.MxObject, uri: string): Promise<boolean> {
129109
return new Promise((resolve, reject) => {
130-
NativeModules.MxFileSystem.read(uri.replace("file://", ""))
110+
NativeFileSystem.read(uri.replace("file://", ""))
131111
.then((nativeBlob: unknown) => {
132112
const blob = new Blob();
133113
Object.assign(blob, { data: nativeBlob });
@@ -169,13 +149,10 @@ export async function TakePicture(
169149
}
170150

171151
async function getPictureMethod(): Promise<
172-
(
173-
options: ImagePickerV2Options | CameraOptions | ImageLibraryOptions,
174-
callback: (response: ImagePickerV2Response | ImagePickerResponse) => void
175-
) => void
152+
(options: CameraOptions | ImageLibraryOptions, callback: (response: ImagePickerResponse) => void) => void
176153
> {
177154
async function handleCameraRequest(): Promise<typeof launchCamera> {
178-
if (Platform.OS === "android" && nativeVersionMajor === 4) {
155+
if (Platform.OS === "android") {
179156
await checkAndMaybeRequestAndroidPermission();
180157
}
181158

@@ -225,38 +202,6 @@ export async function TakePicture(
225202
}
226203
}
227204

228-
function getOptionsV2(): ImagePickerV2Options {
229-
const { maxWidth, maxHeight } = getPictureQuality();
230-
const [language] = getLocales().map(local => local.languageCode);
231-
const isDutch = language === "nl";
232-
233-
return {
234-
mediaType: "photo" as const,
235-
maxWidth,
236-
maxHeight,
237-
noData: true,
238-
title: isDutch ? "Foto toevoegen" : "Select a photo",
239-
cancelButtonTitle: isDutch ? "Annuleren" : "Cancel",
240-
takePhotoButtonTitle: isDutch ? "Foto maken" : "Take photo",
241-
chooseFromLibraryButtonTitle: isDutch ? "Kies uit bibliotheek" : "Choose from library",
242-
permissionDenied: {
243-
title: isDutch
244-
? "Deze app heeft geen toegang tot uw camera of foto bibliotheek"
245-
: "This app does not have access to your camera or photo library",
246-
text: isDutch
247-
? "Ga naar Instellingen > Privacy om toegang tot uw camera en bestanden te verlenen."
248-
: "To enable access, tap Settings > Privacy and turn on Camera and Photos/Storage.",
249-
reTryTitle: isDutch ? "Instellingen" : "Settings",
250-
okTitle: isDutch ? "Annuleren" : "Cancel"
251-
},
252-
storageOptions: {
253-
skipBackup: true,
254-
cameraRoll: false,
255-
privateDirectory: true
256-
}
257-
};
258-
}
259-
260205
function getOptions(): CameraOptions | ImageLibraryOptions {
261206
const { maxWidth, maxHeight } = getPictureQuality();
262207
return {
@@ -293,37 +238,6 @@ export async function TakePicture(
293238
}
294239
}
295240

296-
function handleImagePickerV2Error(error: string): string | undefined {
297-
const ERRORS = {
298-
AndroidPermissionDenied: "Permissions weren't granted",
299-
iOSPhotoLibraryPermissionDenied: "Photo library permissions not granted",
300-
iOSCameraPermissionDenied: "Camera permissions not granted"
301-
};
302-
303-
switch (error) {
304-
case ERRORS.iOSPhotoLibraryPermissionDenied:
305-
showAlert(
306-
"This app does not have access to your photo library",
307-
"To enable access, tap Settings and turn on Photos."
308-
);
309-
return;
310-
311-
case ERRORS.iOSCameraPermissionDenied:
312-
showAlert(
313-
"This app does not have access to your camera",
314-
"To enable access, tap Settings and turn on Camera."
315-
);
316-
return;
317-
318-
case ERRORS.AndroidPermissionDenied:
319-
// Ignore this error because the image picker plugin already shows an alert in this case.
320-
return;
321-
322-
default:
323-
return error;
324-
}
325-
}
326-
327241
function showAlert(title: string, message: string): void {
328242
Alert.alert(
329243
title,

0 commit comments

Comments
 (0)