import React, { useState, useEffect } from "react"; import { ScrollView, View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, Image, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; // Icon library for the media buttons import * as ImagePicker from "expo-image-picker"; // For picking images import * as MediaLibrary from "expo-media-library"; // For accessing media library import { Video } from "expo-av"; // For displaying videos const KontribusiScreen = ({ navigation, route }) => { const { judulPengaduan = "Sampah berantakan", tempatPengaduan = "Jl Raya Madiun Nganjuk", } = route?.params || {}; const [catatan, setCatatan] = useState(""); const [photo, setPhoto] = useState(null); const [video, setVideo] = useState(null); // Request permissions for camera and media library useEffect(() => { const requestPermissions = async () => { // Request permission for media library (Images and Videos) const { status: mediaStatus } = await ImagePicker.requestMediaLibraryPermissionsAsync(); if (mediaStatus !== "granted") { Alert.alert( "Permission required", "You need to grant permission to access your media library." ); } // Optionally, you can also request permission for camera const { status: cameraStatus } = await ImagePicker.requestCameraPermissionsAsync(); if (cameraStatus !== "granted") { Alert.alert( "Permission required", "You need to grant permission to use the camera." ); } }; requestPermissions(); }, []); // Function to pick image const pickImage = async () => { let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, allowsEditing: true, aspect: [4, 3], quality: 1, }); if (!result.canceled) { setPhoto(result.assets[0].uri); // Set the selected photo URI } else { Alert.alert("Tambah foto dibatalkan."); } }; // Function to pick video const pickVideo = async () => { let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Videos, allowsEditing: true, quality: 1, }); if (!result.canceled) { setVideo(result.assets[0].uri); // Set the selected video URI } else { Alert.alert("Pemilihan video dibatalkan."); } }; return ( {/* Title and Back Button */} navigation.goBack()} > KONTRIBUSI SEKARANG {/* Contribution Info Container */} {judulPengaduan} {tempatPengaduan} {/* Add Media Row (Foto & Video) */} Tambah Foto Tambah Video {/* Display selected photo */} {photo && ( )} {/* Display selected video */} {video && ( {/* Koin Message */} Dapatkan +520 Koin {/* Post Button at Bottom */} navigation.navigate("KontribusiBerhasil")} > Posting ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#f9f9f9", }, header: { flexDirection: "row", alignItems: "center", padding: 15, backgroundColor: "#fff", borderBottomLeftRadius: 20, borderBottomRightRadius: 20, }, backButton: { marginRight: 15, marginTop: 40, }, title: { fontSize: 22, color: "#000", fontWeight: "bold", flex: 1, textAlign: "left", marginTop: 40, }, contributionContainer: { padding: 20, backgroundColor: "#fff", marginBottom: 20, borderRadius: 12, shadowColor: "#000", shadowOpacity: 0.1, shadowOffset: { width: 0, height: 4 }, shadowRadius: 4, }, infoBox: { marginBottom: 20, }, infoText1: { fontSize: 22, color: "#333", fontWeight: "700", marginBottom: 5, }, infoText2: { fontSize: 18, color: "#777", fontWeight: "400", }, mediaRow: { flexDirection: "row", justifyContent: "space-between", marginBottom: 25, }, mediaButton: { alignItems: "center", flex: 1, padding: 15, backgroundColor: "#E8F5E9", borderRadius: 10, marginHorizontal: 10, borderWidth: 1, borderColor: "#2D572C", shadowColor: "#000", shadowOpacity: 0.1, shadowOffset: { width: 0, height: 3 }, shadowRadius: 5, elevation: 3, }, mediaButtonText: { fontSize: 14, color: "#2D572C", marginTop: 5, }, input: { height: 100, borderColor: "#2D572C", borderWidth: 1, borderRadius: 8, padding: 12, fontSize: 16, marginBottom: 15, backgroundColor: "#fff", shadowColor: "#000", shadowOpacity: 0.1, shadowOffset: { width: 0, height: 2 }, shadowRadius: 5, elevation: 2, }, koinText: { fontSize: 18, fontWeight: "bold", textAlign: "center", color: "#2D572C", marginBottom: 20, }, postButton: { backgroundColor: "#2D572C", paddingVertical: 15, borderRadius: 10, marginBottom: 20, alignItems: "center", width: "90%", alignSelf: "center", shadowColor: "#000", shadowOpacity: 0.1, shadowOffset: { width: 0, height: 5 }, shadowRadius: 8, elevation: 5, }, postButtonText: { fontSize: 18, color: "#fff", fontWeight: "bold", }, mediaThumbnail: { width: 300, // Adjust size for visibility height: 200, // Adjust size for visibility marginVertical: 10, borderRadius: 8, backgroundColor: "#f0f0f0", }, }); export default KontribusiScreen;