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:
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user