Add camera functionality for task completion photos
- Add camera picker interface to common ImagePicker.kt - Implement camera capture for Android using ActivityResultContracts.TakePicture - Implement camera capture for iOS using UIImagePickerController - Add camera picker stubs for wasmJs, jsMain, and jvmMain platforms - Update CompleteTaskDialog to show both "Take Photo" and "Choose from Library" buttons - Add camera permissions to Android manifest (CAMERA permission, camera intent queries) - Configure Android FileProvider for camera photo sharing - Add camera and photo library usage descriptions to iOS Info.plist - Update iOS CompleteTaskView with native camera picker support - Fix cancel button in CompleteTaskView using @Environment(\.dismiss) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.media.action.IMAGE_CAPTURE" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -32,6 +39,17 @@
|
||||
android:host="reset-password" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- FileProvider for camera photos -->
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.mycrib.platform
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.PickVisualMediaRequest
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
|
||||
@Composable
|
||||
actual fun rememberImagePicker(
|
||||
@@ -50,6 +54,46 @@ actual fun rememberImagePicker(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
actual fun rememberCameraPicker(
|
||||
onImageCaptured: (ImageData) -> Unit
|
||||
): () -> Unit {
|
||||
val context = LocalContext.current
|
||||
|
||||
// Create a temp file URI for the camera to save to
|
||||
val photoUri = remember {
|
||||
val photoFile = File(context.cacheDir, "camera_photo_${System.currentTimeMillis()}.jpg")
|
||||
FileProvider.getUriForFile(
|
||||
context,
|
||||
"${context.packageName}.fileprovider",
|
||||
photoFile
|
||||
)
|
||||
}
|
||||
|
||||
val launcher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.TakePicture()
|
||||
) { success: Boolean ->
|
||||
if (success) {
|
||||
try {
|
||||
val inputStream = context.contentResolver.openInputStream(photoUri)
|
||||
val bytes = inputStream?.readBytes()
|
||||
inputStream?.close()
|
||||
|
||||
if (bytes != null) {
|
||||
val fileName = "camera_${System.currentTimeMillis()}.jpg"
|
||||
onImageCaptured(ImageData(bytes, fileName))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
launcher.launch(photoUri)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFileNameFromUri(context: android.content.Context, uri: Uri): String {
|
||||
var fileName = "image_${System.currentTimeMillis()}.jpg"
|
||||
|
||||
|
||||
4
composeApp/src/androidMain/res/xml/file_paths.xml
Normal file
4
composeApp/src/androidMain/res/xml/file_paths.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<cache-path name="camera_images" path="/" />
|
||||
</paths>
|
||||
Reference in New Issue
Block a user