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
4 changes: 2 additions & 2 deletions formulus/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ android {
applicationId = "org.opendataensemble.formulus"
minSdk = rootProject.ext.minSdkVersion
targetSdk = rootProject.ext.targetSdkVersion
versionCode = 76
versionName = "1.3.3"
versionCode = 80
versionName = "1.3.4"

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", (findProperty("newArchEnabled") ?: "false").toString()

Expand Down
9 changes: 1 addition & 8 deletions formulus/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@

<!-- Camera permission for QR scanning (react-native-camera-kit-no-google) -->
<uses-permission android:name="android.permission.CAMERA" />

<!-- Storage permissions for react-native-image-picker -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- Optional: Media permissions for Android 13+ -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />


<!-- Location permissions for geolocation services -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand Down
2 changes: 1 addition & 1 deletion formulus/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
minSdkVersion = 24
compileSdkVersion = 36
targetSdkVersion = 36
ndkVersion = "27.1.12297006"
ndkVersion = "28.0.13004108"
kotlinVersion = "2.1.20"
}
repositories {
Expand Down
8 changes: 4 additions & 4 deletions formulus/ios/Formulus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 76;
CURRENT_PROJECT_VERSION = 80;
DEVELOPMENT_TEAM = 57WY3GA5K7;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Formulus/Info.plist;
Expand All @@ -321,7 +321,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.3.3;
MARKETING_VERSION = 1.3.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand All @@ -347,7 +347,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 76;
CURRENT_PROJECT_VERSION = 80;
DEVELOPMENT_TEAM = 57WY3GA5K7;
INFOPLIST_FILE = Formulus/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Formulus;
Expand All @@ -357,7 +357,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.3.3;
MARKETING_VERSION = 1.3.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down
2 changes: 1 addition & 1 deletion formulus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formulus-app",
"version": "1.3.3",
"version": "1.3.4",
"packageManager": "pnpm@11.22.0",
"type": "module",
"private": true,
Expand Down
159 changes: 141 additions & 18 deletions formulus/src/webview/FormulusMessageHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import {
pick,
types,
keepLocalCopy,
isErrorWithCode,
errorCodes,
} from '@react-native-documents/picker';
Expand Down Expand Up @@ -311,19 +312,6 @@ export function createFormulusMessageHandlers(): FormulusMessageHandlers {

return new Promise(resolve => {
try {
if (!ImagePicker || !ImagePicker.launchImageLibrary) {
console.error(
'react-native-image-picker not available or not properly linked',
);
resolve({
fieldId,
status: 'error',
message:
'Image picker functionality not available. Please ensure react-native-image-picker is properly installed and linked.',
});
return;
}

// Image picker options for react-native-image-picker
const options = {
mediaType: 'photo' as const,
Expand Down Expand Up @@ -436,6 +424,109 @@ export function createFormulusMessageHandlers(): FormulusMessageHandlers {
}
};

const selectImageWithSystemPicker = async () => {
try {
const [result] = await pick({
type: [types.images],
mode: 'import',
allowMultiSelection: false,
});

const originalName =
typeof result.name === 'string' && result.name.trim().length > 0
? result.name.trim()
: 'image';
const extensionMatch = /\.([^.\\/]{1,32})$/.exec(originalName);
const subtype = result.type
?.split('/')[1]
?.split('+')[0]
?.replace(/[^a-z0-9]/gi, '');
const extension =
extensionMatch?.[1]?.toLowerCase() ||
subtype?.toLowerCase() ||
'jpg';
const imageGuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
/[xy]/g,
c => {
const r = Math.floor(Math.random() * 16);
const v = c === 'x' ? r : (r % 4) + 8;
return v.toString(16);
},
);
const filename = `${imageGuid}.${extension}`;
const attachmentsDirectory = `${RNFS.DocumentDirectoryPath}/attachments`;
const draftDirectory = `${attachmentsDirectory}/draft`;
const draftFilePath = `${draftDirectory}/${filename}`;

// Android pick() returns a content:// URI, which RNFS cannot read
// as a plain path. keepLocalCopy converts it into a local file in
// the app cache, then we move it into app-private attachment
// storage (move = rename on the same volume, no double copy).
const [localCopy] = await keepLocalCopy({
files: [{ uri: result.uri, fileName: filename }],
destination: 'cachesDirectory',
});

if (localCopy.status !== 'success') {
resolve({
fieldId,
status: 'error',
message:
localCopy.copyError ||
'Failed to import the selected image',
});
return;
}

await RNFS.mkdir(attachmentsDirectory);
await RNFS.mkdir(draftDirectory);
await RNFS.moveFile(localCopy.localUri, draftFilePath);

resolve({
fieldId,
status: 'success',
data: {
type: 'image',
id: imageGuid,
filename,
uri: draftFilePath,
url: `file://${draftFilePath}`,
timestamp: new Date().toISOString(),
metadata: {
size: result.size || 0,
mimeType: result.type || 'image/*',
source: 'android-storage-access-framework',
originalFileName: originalName,
persistentStorage: true,
storageLocation: 'draft_attachments',
syncReady: false,
},
},
});
} catch (error) {
if (
isErrorWithCode(error) &&
error.code === errorCodes.OPERATION_CANCELED
) {
resolve({
fieldId,
status: 'cancelled',
message: 'Image selection cancelled by user',
});
return;
}

resolve({
fieldId,
status: 'error',
message:
error instanceof Error
? error.message
: 'Failed to select an image',
});
}
};

// Show action sheet with camera and gallery options
Alert.alert(
i18n.t('media.selectImageTitle'),
Expand All @@ -445,6 +536,14 @@ export function createFormulusMessageHandlers(): FormulusMessageHandlers {
text: i18n.t('media.camera'),
onPress: () => {
void (async () => {
if (!ImagePicker.launchCamera) {
resolve({
fieldId,
status: 'error',
message: 'Camera functionality is not available.',
});
return;
}
const perm = await ensureCameraPermission();
if (perm !== RESULTS.GRANTED) {
resolve({
Expand All @@ -467,10 +566,20 @@ export function createFormulusMessageHandlers(): FormulusMessageHandlers {
{
text: i18n.t('media.gallery'),
onPress: () => {
ImagePicker.launchImageLibrary(
options,
handleImagePickerResponse,
);
if (Platform.OS === 'android') {
void selectImageWithSystemPicker();
} else if (ImagePicker.launchImageLibrary) {
ImagePicker.launchImageLibrary(
options,
handleImagePickerResponse,
);
} else {
resolve({
fieldId,
status: 'error',
message: 'Image picker functionality is not available.',
});
}
},
},
{
Expand Down Expand Up @@ -909,10 +1018,24 @@ export function createFormulusMessageHandlers(): FormulusMessageHandlers {
const draftDirectory = `${attachmentsDirectory}/draft`;
const draftFilePath = `${draftDirectory}/${basename}`;

const [localCopy] = await keepLocalCopy({
files: [{ uri: result.uri, fileName: basename }],
destination: 'cachesDirectory',
});

if (localCopy.status !== 'success') {
return {
fieldId,
status: 'error' as const,
message:
localCopy.copyError || 'Failed to import the selected file',
};
}

await RNFS.mkdir(attachmentsDirectory);
await RNFS.mkdir(draftDirectory);

await RNFS.copyFile(result.uri, draftFilePath);
await RNFS.moveFile(localCopy.localUri, draftFilePath);

const webViewUrl = `file://${draftFilePath}`;

Expand Down
Loading