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
17 changes: 6 additions & 11 deletions configs/jsactions/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ export default async args => {
types: ["mendix-client", "react-native"],
allowSyntheticDefaultImports: true,
compilerOptions: {
newLine: "CRLF"
newLine: "CRLF",
// `react-native-nitro-geolocation` ships no compiled JS; its entry points are `.tsx`
// (`main: "src/index"`, `browser: "src/index.web.tsx"`). The TS plugin therefore needs
// `jsx` set to parse those `.tsx` files, otherwise the build fails with
// `TS6142: Module ... was resolved to '.../src/index.tsx', but '--jsx' is not set`.
jsx: "react-native"
Comment thread
vadymv-mendix marked this conversation as resolved.
}
});

Expand Down Expand Up @@ -92,16 +97,6 @@ export default async args => {
overwrite: true
}
);
} else if (args.configProject === "nanoflowcommons") {
// `invariant` is being used silently by @react-native-community/geolocation; it is not listed as a dependency nor peerDependency.
// https://github.dev/react-native-geolocation/react-native-geolocation/blob/1786929f2be581da91082ff857c2393da5e597b3/js/implementation.native.js#L13
await copyAsync(
dirname(require.resolve("invariant")),
join(outDir, "node_modules", "invariant"),
{
overwrite: true
}
);
}

// this is helpful to copy the files and folders to a test project path for dev/testing purposes.
Expand Down
5 changes: 5 additions & 0 deletions packages/jsActions/nanoflow-actions-native/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]

- Fixed an issue where base64-to-image decoding was failing.
- Migrated the geolocation actions from `@react-native-community/geolocation` to `react-native-nitro-geolocation`.

### Fixed

- Fixed a resource leak in `Get current location with minimum accuracy` where the timeout and location watcher were not cleared on error.

## [7.2.0] Nanoflow Commons - 2026-7-3

Expand Down
6 changes: 3 additions & 3 deletions packages/jsActions/nanoflow-actions-native/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nanoflow-actions-native",
"moduleName": "Nanoflow Commons",
"version": "7.1.0",
"version": "7.3.0",
"license": "Apache-2.0",
"copyright": "© Mendix Technology BV 2022. All rights reserved.",
"repository": {
Expand All @@ -27,9 +27,9 @@
},
"dependencies": {
"@react-native-async-storage/async-storage": "2.2.0",
"@react-native-community/geolocation": "3.4.0",
"invariant": "^2.2.4",
"js-base64": "~3.7.2",
"react-native-nitro-geolocation": "1.4.3",
"react-native-nitro-modules": "0.36.1",
"react-native-permissions": "5.5.1",
"react-native-geocoder": "0.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import { Big } from "big.js";
import Geolocation, {
GeolocationError,
GeolocationOptions,
GeolocationResponse
} from "@react-native-community/geolocation";

import type { Platform, NativeModules } from "react-native";
import type { GeoError, GeoPosition, GeoOptions } from "../../typings/Geolocation";
import { getCurrentPosition, GeolocationResponse, LocationRequestOptions } from "react-native-nitro-geolocation";
Comment thread
stelselim marked this conversation as resolved.

// BEGIN EXTRA CODE
// END EXTRA CODE
Expand All @@ -39,94 +32,114 @@ export async function GetCurrentLocation(
): Promise<mendix.lib.MxObject> {
// BEGIN USER CODE

let reactNativeModule: { NativeModules: typeof NativeModules; Platform: typeof Platform } | undefined;
let geolocationModule: typeof import("@react-native-community/geolocation").default | Geolocation;
const isReactNative = navigator && navigator.product === "ReactNative";
const isWeb = navigator && navigator.geolocation;

if (navigator && navigator.product === "ReactNative") {
reactNativeModule = require("react-native");
if (!isReactNative && !isWeb) {
return Promise.reject(new Error("Geolocation module could not be found"));
}

if (!reactNativeModule) {
return Promise.reject(new Error("React Native module could not be found"));
}
// We keep a manual web branch (backed by `navigator.geolocation`) rather than relying on the
// library's web entry, because it is not guaranteed that the Mendix web client resolves the
// package's `browser`/`exports` condition. If that is ever confirmed, this branch can be dropped.
Comment thread
stelselim marked this conversation as resolved.
const options = buildLocationOptions(timeout, maximumAge, highAccuracy);
try {
let position: GeolocationResponse;

if (reactNativeModule.NativeModules.RNFusedLocation) {
geolocationModule = (await import("@react-native-community/geolocation")).default;
} else if (reactNativeModule.NativeModules.RNCGeolocation) {
geolocationModule = Geolocation;
if (isReactNative) {
position = await getCurrentPosition(options);
} else {
return Promise.reject(new Error("Geolocation module could not be found"));
position = await new Promise<GeolocationResponse>((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
pos => resolve(normalizeWebPosition(pos)),
err => reject(err),
{
timeout: options.timeout,
maximumAge: options.maximumAge,
enableHighAccuracy: highAccuracy ?? false
}
);
});
}
} else if (navigator && navigator.geolocation) {
geolocationModule = navigator.geolocation;
Comment thread
vadymv-mendix marked this conversation as resolved.
} else {
return Promise.reject(new Error("Geolocation module could not be found"));
}

return new Promise((resolve, reject) => {
const options = getOptions();
geolocationModule?.getCurrentPosition(onSuccess, onError, options);

function onSuccess(position: GeolocationResponse | GeoPosition): void {
return new Promise((resolve, reject) => {
mx.data.create({
entity: "NanoflowCommons.Geolocation",
callback: mxObject => {
const geolocation = mapPositionToMxObject(mxObject, position);
resolve(geolocation);
resolve(mapPositionToMxObject(mxObject, position));
},
error: () =>
reject(new Error("Could not create 'NanoflowCommons.Geolocation' object to store location"))
});
}
});
} catch (error: any) {
const message = error?.message ?? String(error);
return Promise.reject(new Error(`Could not get current location: ${message}`));
}

function buildLocationOptions(
timeout: Big | undefined,
maximumAge: Big | undefined,
highAccuracy: boolean | undefined
): LocationRequestOptions {
let timeoutNumber = timeout ? timeout.toNumber() : undefined;
const maximumAgeNumber = maximumAge ? maximumAge.toNumber() : undefined;

function onError(error: GeolocationError | GeoError): void {
return reject(new Error(error.message));
// If the timeout is 0 or undefined (empty), it causes a crash on iOS.
// If the timeout is undefined (empty); we set timeout to 30 sec (default timeout)
// If the timeout is 0; we set timeout to 1 hour (no timeout)
if (isReactNative && require("react-native").Platform.OS === "ios") {
if (timeoutNumber === undefined) {
timeoutNumber = 30000;
} else if (timeoutNumber === 0) {
timeoutNumber = 3600000;
}
}

function getOptions(): GeolocationOptions | GeoOptions {
let timeoutNumber = timeout && Number(timeout.toString());
const maximumAgeNumber = maximumAge && Number(maximumAge.toString());
return {
timeout: timeoutNumber,
maximumAge: maximumAgeNumber,
accuracy: highAccuracy ? { android: "high", ios: "best" } : { android: "balanced", ios: "hundredMeters" }
};
}

// If the timeout is 0 or undefined (empty), it causes a crash on iOS.
// If the timeout is undefined (empty); we set timeout to 30 sec (default timeout)
// If the timeout is 0; we set timeout to 1 hour (no timeout)
if (reactNativeModule?.Platform.OS === "ios") {
if (timeoutNumber === undefined) {
timeoutNumber = 30000;
} else if (timeoutNumber === 0) {
timeoutNumber = 3600000;
}
}
// NOTE: `normalizeWebPosition` is duplicated verbatim in `GetCurrentLocationMinimumAccuracy.ts`.
// The Mendix action model does not allow sharing code across action files, so if you change this
// function, keep the copy in the other action in sync.
function normalizeWebPosition(pos: GeolocationPosition): GeolocationResponse {
Comment thread
vadymv-mendix marked this conversation as resolved.
return {
coords: {
latitude: pos.coords.latitude,
longitude: pos.coords.longitude,
altitude: pos.coords.altitude ?? null,
accuracy: pos.coords.accuracy,
altitudeAccuracy: pos.coords.altitudeAccuracy ?? null,
heading: pos.coords.heading ?? null,
speed: pos.coords.speed ?? null
},
timestamp: pos.timestamp
};
}

return {
timeout: timeoutNumber,
maximumAge: maximumAgeNumber,
enableHighAccuracy: highAccuracy
};
function mapPositionToMxObject(mxObject: mendix.lib.MxObject, pos: GeolocationResponse): mendix.lib.MxObject {
mxObject.set("Timestamp", new Date(pos.timestamp));
mxObject.set("Latitude", new Big(pos.coords.latitude.toFixed(8)));
mxObject.set("Longitude", new Big(pos.coords.longitude.toFixed(8)));
mxObject.set("Accuracy", new Big(pos.coords.accuracy.toFixed(8)));
if (pos.coords.altitude != null) {
mxObject.set("Altitude", new Big(pos.coords.altitude.toFixed(8)));
}

function mapPositionToMxObject(
mxObject: mendix.lib.MxObject,
position: GeolocationResponse | GeoPosition
): mendix.lib.MxObject {
mxObject.set("Timestamp", new Date(position.timestamp));
mxObject.set("Latitude", new Big(position.coords.latitude.toFixed(8)));
mxObject.set("Longitude", new Big(position.coords.longitude.toFixed(8)));
mxObject.set("Accuracy", new Big(position.coords.accuracy.toFixed(8)));
if (position.coords.altitude != null) {
mxObject.set("Altitude", new Big(position.coords.altitude.toFixed(8)));
}
if (position.coords.altitudeAccuracy != null && position.coords.altitudeAccuracy !== -1) {
mxObject.set("AltitudeAccuracy", new Big(position.coords.altitudeAccuracy.toFixed(8)));
}
if (position.coords.heading != null && position.coords.heading !== -1) {
mxObject.set("Heading", new Big(position.coords.heading.toFixed(8)));
}
if (position.coords.speed != null && position.coords.speed !== -1) {
mxObject.set("Speed", new Big(position.coords.speed.toFixed(8)));
}
return mxObject;
if (pos.coords.altitudeAccuracy != null && pos.coords.altitudeAccuracy !== -1) {
mxObject.set("AltitudeAccuracy", new Big(pos.coords.altitudeAccuracy.toFixed(8)));
}
if (pos.coords.heading != null && pos.coords.heading !== -1) {
mxObject.set("Heading", new Big(pos.coords.heading.toFixed(8)));
}
});
if (pos.coords.speed != null && pos.coords.speed !== -1) {
mxObject.set("Speed", new Big(pos.coords.speed.toFixed(8)));
}
return mxObject;
}

// END USER CODE
}
Loading
Loading