Commit 10bf147d by tungnq

TODO: Đã hoàn thiện giao diện phần tạo văn bản đi

parent fa64995b
import React, {useState} from 'react'; import React, { useEffect, useState } from 'react';
import { import {
View, View,
Text, Text,
TouchableOpacity, TouchableOpacity,
StyleSheet, StyleSheet,
FlatList,
Image, Image,
ScrollView, ScrollView,
} from 'react-native'; } from 'react-native';
import R from '../../assets/R'; import R from '../../assets/R';
const Dropdown = ({items, placeholder = 'Chọn...', onSelect, height}) => {
const Dropdown = ({
items = [],
placeholder = 'Chọn...',
onSelect,
height,
backgroundColor,
// mới thêm
editable = true,
disabledBackgroundColor = R.colors.blue1,
disabledTextColor = '#999',
disabledIconColor = '#999',
}) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [selected, setSelected] = useState(null); const [selected, setSelected] = useState(null);
const handleSelect = item => { const headerHeight = height ?? 35;
useEffect(() => {
if (!editable && isOpen) setIsOpen(false);
}, [editable, isOpen]);
const handleToggle = () => {
if (!editable) return;
setIsOpen(prev => !prev);
};
const handleSelect = (item) => {
if (!editable) return;
setSelected(item); setSelected(item);
setIsOpen(false); setIsOpen(false);
if (onSelect) onSelect(item); onSelect && onSelect(item);
}; };
const resolvedBg = editable ? (backgroundColor || '#fff') : disabledBackgroundColor;
const resolvedTextColor = editable ? '#333' : disabledTextColor;
const resolvedIconTint = editable ? '#333' : disabledIconColor;
const resolvedBorderColor = editable ? R.colors?.grayBorderInputTextHeader || '#ccc' : '#ddd';
return ( return (
<View style={[styles.container]}> <View style={styles.container}>
{/* Nút hiển thị */} {/* Header */}
<TouchableOpacity <TouchableOpacity
style={[styles.dropdownHeader,{height:height}]} activeOpacity={editable ? 0.7 : 1}
onPress={() => setIsOpen(!isOpen)}> onPress={handleToggle}
<Text style={styles.dropdownHeaderText}> disabled={!editable}
style={[
styles.dropdownHeader,
{
height: headerHeight,
backgroundColor: resolvedBg,
borderColor: resolvedBorderColor,
opacity: editable ? 1 : 0.8,
},
]}
>
<Text style={[styles.dropdownHeaderText, { color: resolvedTextColor }]}>
{selected ? selected.label : placeholder} {selected ? selected.label : placeholder}
</Text> </Text>
<Image source={R.images.icDrop} style={styles.imageIcon} /> <Image
source={R.images.icDrop}
style={[styles.imageIcon, { tintColor: resolvedIconTint }]}
/>
</TouchableOpacity> </TouchableOpacity>
{/* Danh sách xổ xuống */} {/* List */}
{isOpen && ( {isOpen && (
<View <View
style={[ style={[
styles.dropdownList, styles.dropdownList,
{position: 'absolute', top: 35, left: 0, right: 0, zIndex: 999}, {
]}> top: headerHeight,
{/* <FlatList backgroundColor: '#fff',
nestedScrollEnabled={true} borderColor: '#e5e5e5',
data={items} },
keyExtractor={(item) => item.id.toString()} ]}
renderItem={({ item }) => ( >
<ScrollView style={{ maxHeight: 220 }}>
{items.map((item) => (
<TouchableOpacity <TouchableOpacity
key={String(item.id)}
style={styles.dropdownItem} style={styles.dropdownItem}
onPress={() => handleSelect(item)} onPress={() => handleSelect(item)}
> >
<Text style={styles.dropdownItemText}>{item.label}</Text> <Text style={styles.dropdownItemText}>{item.label}</Text>
</TouchableOpacity> </TouchableOpacity>
)}
/> */}
<ScrollView style={{maxHeight: 200}}>
{items.map(item => (
<TouchableOpacity
key={item.id.toString()}
style={styles.dropdownItem}
onPress={() => handleSelect(item)}>
<Text style={styles.dropdownItemText}>{item.label}</Text>
</TouchableOpacity>
))} ))}
</ScrollView> </ScrollView>
</View> </View>
...@@ -72,29 +108,35 @@ export default Dropdown; ...@@ -72,29 +108,35 @@ export default Dropdown;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
width: '100%', width: '100%',
position: 'relative',
}, },
dropdownHeader: { dropdownHeader: {
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
borderWidth: 1, borderWidth: 1,
borderColor: R.colors.grayBorderInputTextHeader,
borderRadius: 5, borderRadius: 5,
backgroundColor: '#fff',
height: 35,
paddingHorizontal: 15, paddingHorizontal: 15,
}, },
dropdownHeaderText: { dropdownHeaderText: {
fontSize: 12, fontSize: 12,
color: '#333',
}, },
dropdownList: { dropdownList: {
position: 'absolute',
left: 0,
right: 0,
zIndex: 999,
elevation: 8, // Android
borderWidth: 1, borderWidth: 1,
borderColor: '#ccc', borderRadius: 6,
backgroundColor: '#fff', shadowColor: '#000', // iOS
shadowOpacity: 0.1,
shadowRadius: 8,
shadowOffset: { width: 0, height: 4 },
}, },
dropdownItem: { dropdownItem: {
padding: 5, paddingVertical: 8,
paddingHorizontal: 12,
borderBottomWidth: 1, borderBottomWidth: 1,
borderBottomColor: '#eee', borderBottomColor: '#eee',
}, },
...@@ -106,6 +148,5 @@ const styles = StyleSheet.create({ ...@@ -106,6 +148,5 @@ const styles = StyleSheet.create({
width: 20, width: 20,
height: 20, height: 20,
resizeMode: 'contain', resizeMode: 'contain',
tintColor: '#333',
}, },
}); });
...@@ -51,7 +51,10 @@ const TextField = props => { ...@@ -51,7 +51,10 @@ const TextField = props => {
placeholder={placeholder} placeholder={placeholder}
maxLength={maxLength ? maxLength : 256} maxLength={maxLength ? maxLength : 256}
placeholderTextColor={R.colors.gray} placeholderTextColor= {
editable === false
? (backgroundColor || R.colors.black) // khi disabled thì lấy màu xám
: backgroundColor }
editable={editable != null ? editable : true} editable={editable != null ? editable : true}
secureTextEntry={isPassword} secureTextEntry={isPassword}
autoCapitalize="none" autoCapitalize="none"
...@@ -68,7 +71,9 @@ const TextField = props => { ...@@ -68,7 +71,9 @@ const TextField = props => {
fontSize: fontSize, fontSize: fontSize,
paddingVertical: 5, paddingVertical: 5,
paddingHorizontal: 10, paddingHorizontal: 10,
backgroundColor: backgroundColor, backgroundColor: editable === false
? (backgroundColor || R.colors.blue1) // khi disabled thì lấy màu xám
: backgroundColor, // khi enable thì lấy màu bạn truyền,
}} }}
/> />
{error && <View {error && <View
......
...@@ -54,7 +54,10 @@ const TextField = props => { ...@@ -54,7 +54,10 @@ const TextField = props => {
multiline={true} multiline={true}
numberOfLines={numberOfLines} numberOfLines={numberOfLines}
onFocus={onFocus} onFocus={onFocus}
placeholderTextColor={R.colors.gray} placeholderTextColor= {
editable === false
? (backgroundColor || R.colors.black) // khi disabled thì lấy màu xám
: backgroundColor || R.colors.gray }
autoCapitalize="none" autoCapitalize="none"
style={{ style={{
textAlignVertical: 'top', textAlignVertical: 'top',
...@@ -68,8 +71,9 @@ const TextField = props => { ...@@ -68,8 +71,9 @@ const TextField = props => {
fontSize: fontSizePlaceHolder, fontSize: fontSizePlaceHolder,
paddingVertical: 10, paddingVertical: 10,
paddingHorizontal: 10, paddingHorizontal: 10,
backgroundColor: backgroundColor, backgroundColor: editable === false
? (backgroundColor || R.colors.blue1) // khi disabled thì lấy màu xám
: backgroundColor, // khi enable thì lấy màu bạn truyền,
}} }}
/> />
</View> </View>
......
...@@ -30,6 +30,7 @@ row_1:{ ...@@ -30,6 +30,7 @@ row_1:{
fontFamily:R.fonts.fontRegular, fontFamily:R.fonts.fontRegular,
color:R.colors.black, color:R.colors.black,
}, },
containerDropdown:{ containerDropdown:{
marginBottom:10, marginBottom:10,
position: 'relative', position: 'relative',
...@@ -84,6 +85,12 @@ row_1:{ ...@@ -84,6 +85,12 @@ row_1:{
borderWidth:1, borderWidth:1,
borderColor:R.colors.blue1, borderColor:R.colors.blue1,
height:80 height:80
},
textBtn:{
fontSize: R.fontsize.fontSizeContent,
fontWeight: '400',
fontFamily:R.fonts.fontRegular,
color:R.colors.black,
} }
......
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