BlueWallet/components/SettingsBlockExplorerCustomUrlListItem.tsx

90 lines
2.5 KiB
TypeScript
Raw Normal View History

import React from 'react';
2024-09-26 08:36:51 +02:00
import { StyleSheet, TextInput, View, Switch } from 'react-native';
import { ListItem } from '@rneui/themed';
import { useTheme } from './themes';
import loc from '../loc';
2024-09-26 08:36:51 +02:00
interface SettingsBlockExplorerCustomUrlItemProps {
isCustomEnabled: boolean;
onSwitchToggle: (value: boolean) => void;
customUrl: string;
onCustomUrlChange: (url: string) => void;
onSubmitCustomUrl: () => void;
2024-09-24 04:36:14 +02:00
inputRef?: React.RefObject<TextInput>;
}
2024-09-26 08:36:51 +02:00
const SettingsBlockExplorerCustomUrlItem: React.FC<SettingsBlockExplorerCustomUrlItemProps> = ({
isCustomEnabled,
onSwitchToggle,
customUrl,
onCustomUrlChange,
onSubmitCustomUrl,
2024-09-24 04:36:14 +02:00
inputRef,
}) => {
const { colors } = useTheme();
return (
2024-09-26 08:36:51 +02:00
<>
<ListItem containerStyle={[styles.container, { backgroundColor: colors.background }]} bottomDivider>
<ListItem.Content>
<ListItem.Title style={[styles.title, { color: colors.text }]}>{loc.settings.block_explorer_preferred}</ListItem.Title>
</ListItem.Content>
<Switch
accessible
accessibilityRole="switch"
accessibilityState={{ checked: isCustomEnabled }}
onValueChange={onSwitchToggle}
value={isCustomEnabled}
/>
</ListItem>
2024-09-26 08:36:51 +02:00
{isCustomEnabled && (
<View style={[styles.uriContainer, { borderColor: colors.formBorder, backgroundColor: colors.inputBackgroundColor }]}>
<TextInput
2024-09-24 04:36:14 +02:00
ref={inputRef}
value={customUrl}
placeholder={loc._.enter_url}
onChangeText={onCustomUrlChange}
numberOfLines={1}
2024-09-26 08:36:51 +02:00
style={[styles.uriText, { color: colors.text }]}
placeholderTextColor={colors.placeholderTextColor}
textContentType="URL"
clearButtonMode="while-editing"
autoCapitalize="none"
autoCorrect={false}
underlineColorAndroid="transparent"
onSubmitEditing={onSubmitCustomUrl}
2024-09-26 08:36:51 +02:00
editable={isCustomEnabled}
/>
</View>
)}
2024-09-26 08:36:51 +02:00
</>
);
};
2024-09-26 08:36:51 +02:00
export default SettingsBlockExplorerCustomUrlItem;
const styles = StyleSheet.create({
2024-09-26 08:36:51 +02:00
container: {
minHeight: 60,
paddingVertical: 10,
},
title: {
fontSize: 16,
fontWeight: '500',
},
2024-09-26 08:36:51 +02:00
uriContainer: {
flexDirection: 'row',
borderWidth: 1,
borderRadius: 4,
2024-09-26 08:36:51 +02:00
marginHorizontal: 15,
marginVertical: 10,
paddingHorizontal: 10,
alignItems: 'center',
},
uriText: {
flex: 1,
minHeight: 36,
},
});