Commit 80e80822 by tungnq

TODO: Bổ sung thư viện lấy ảnh từ thiết bị

parent f1e4487a
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application <application
android:name=".MainApplication" android:name=".MainApplication"
......
...@@ -23,6 +23,12 @@ ...@@ -23,6 +23,12 @@
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string> <string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<key>NSPhotoLibraryUsageDescription</key>
<string>Cho phép ng dng truy cp thư vin nh ca bn</string>
<key>NSCameraUsageDescription</key>
<string>Cho phép ng dng s dng camera ca bn</string>
<key>NSMicrophoneUsageDescription</key>
<string>Cho phép ng dng s dng microphone ca bn</string>
<true/> <true/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>
<dict> <dict>
......
...@@ -25,6 +25,7 @@ import {sha256, sha224} from 'js-sha256'; ...@@ -25,6 +25,7 @@ import {sha256, sha224} from 'js-sha256';
import {RFValue} from 'react-native-responsive-fontsize'; import {RFValue} from 'react-native-responsive-fontsize';
var Sound = require('react-native-sound'); var Sound = require('react-native-sound');
export const soundStart = () => { export const soundStart = () => {
var whoosh = new Sound('sond_noti.mp3', Sound.MAIN_BUNDLE, error => { var whoosh = new Sound('sond_noti.mp3', Sound.MAIN_BUNDLE, error => {
if (error) { if (error) {
......
...@@ -7,23 +7,35 @@ const CardButtonImage = ({ ...@@ -7,23 +7,35 @@ const CardButtonImage = ({
text = 'Tải ảnh ở đây', text = 'Tải ảnh ở đây',
width, width,
height = 150, height = 150,
image,
disabled = false, disabled = false,
}) => { }) => {
return ( return (
<TouchableOpacity <TouchableOpacity
style={[ style={[
styles.container_image, styles.container_image ,
{width, height}, {
width,
height,
borderStyle: 'dashed',
borderColor: R.colors.gray150,
},
disabled && styles.disabled, disabled && styles.disabled,
]} ]}
onPress={onPress} onPress={onPress}
disabled={disabled} disabled={disabled}
activeOpacity={0.7}> activeOpacity={0.7}>
{image ? (
<Image source={{uri: image}} style={{width: '100%', height: '100%' }} resizeMode="contain" />
) : (
<View style={{justifyContent: 'center', alignItems: 'center'}}>
<View style={styles.image_placeholder}></View> <View style={styles.image_placeholder}></View>
<View> <View>
<Image source={R.images.icImageDownload} style={styles.image} /> <Image source={R.images.icImageDownload} style={styles.image} />
</View> </View>
<Text style={styles.placeholder_text}>{text}</Text> <Text style={styles.placeholder_text}>{text}</Text>
</View>
)}
</TouchableOpacity> </TouchableOpacity>
); );
}; };
......
import React, { useState ,useMemo} from 'react'; import React, { useState ,useMemo} from 'react';
import {Text, View, StyleSheet} from 'react-native'; import {Text, View, StyleSheet} from 'react-native';
import CertificateRegistrationView from './view'; import CertificateRegistrationView from './view';
import {launchCamera, launchImageLibrary} from 'react-native-image-picker';
const CertificateRegistration = (props) => { const CertificateRegistration = (props) => {
const [titleHeader,setTitleHeader]= useState('CertificateRegisitor') const [titleHeader,setTitleHeader]= useState('CertificateRegisitor')
const [isSelected, setSelection] = useState(false); const [isSelected, setSelection] = useState(false);
const [selectedValue, setSelectedValue] = useState(null); const [selectedValue, setSelectedValue] = useState(null);
const [image, setImage] = useState(null);
const [dataListCertificate, setdataListCertificate]= useState([ const [dataListCertificate, setdataListCertificate]= useState([
{ {
id: 1, id: 1,
...@@ -78,6 +79,28 @@ const CertificateRegistration = (props) => { ...@@ -78,6 +79,28 @@ const CertificateRegistration = (props) => {
setSelectedValue(item.value); setSelectedValue(item.value);
}; };
const openImagePicker = () => {
const options = {
mediaType: 'photo',
quality: 1,
};
launchImageLibrary (options,(res)=>{
if (res.didCancel) {
console.log('User cancelled image picker');
} else if (res.errorCode) {
console.log('ImagePicker Error: ', res.errorCode);
} else {
// Lấy URI từ asset đầu tiên
const imageUri = res.assets && res.assets[0] ? res.assets[0].uri : null;
// Lưu URI vào state
setImage(imageUri);
}
})
};
return ( return (
<CertificateRegistrationView <CertificateRegistrationView
titleHeader={titleHeader} titleHeader={titleHeader}
...@@ -86,6 +109,8 @@ const CertificateRegistration = (props) => { ...@@ -86,6 +109,8 @@ const CertificateRegistration = (props) => {
onSelect={handleSelect} onSelect={handleSelect}
isSelected={isSelected} isSelected={isSelected}
setSelection={setSelection} setSelection={setSelection}
image={image}
openImagePicker={openImagePicker}
/> />
); );
}; };
......
...@@ -54,11 +54,11 @@ const styles = StyleSheet.create({ ...@@ -54,11 +54,11 @@ const styles = StyleSheet.create({
marginTop: 3, marginTop: 3,
marginBottom: 15, marginBottom: 15,
borderWidth: 1, borderWidth: 1,
borderRadius: 10,
paddingVertical:5,
borderColor: R.colors.blue500, borderColor: R.colors.blue500,
borderStyle: 'dashed',
borderRadius: 15,
backgroundColor: R.colors.white, backgroundColor: R.colors.white,
padding: 16,
flexDirection: 'row', flexDirection: 'row',
flex: 1, flex: 1,
}, },
......
...@@ -11,7 +11,7 @@ import CustomTextInput from '../../components/Input/TextFieldCus'; ...@@ -11,7 +11,7 @@ import CustomTextInput from '../../components/Input/TextFieldCus';
import styles from './style'; import styles from './style';
const CertificateRegistrationView = props => { const CertificateRegistrationView = props => {
const {titleHeader, dataList, isSelected, setSelection} = props; const {titleHeader, dataList, isSelected, setSelection, image, openImagePicker} = props;
const renderBody = () => { const renderBody = () => {
return ( return (
<ScrollView <ScrollView
...@@ -121,7 +121,7 @@ const CertificateRegistrationView = props => { ...@@ -121,7 +121,7 @@ const CertificateRegistrationView = props => {
<Text style={styles.text_title_register}> <Text style={styles.text_title_register}>
nh chng ch <Text style={{color: 'red',}}>*</Text> nh chng ch <Text style={{color: 'red',}}>*</Text>
</Text> </Text>
<CardButtonImage /> <CardButtonImage onPress={openImagePicker} image={image}/>
<View style={styles.footer}> <View style={styles.footer}>
<CheckBox <CheckBox
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment