BlueWallet/BlueComponents.js

221 lines
5.8 KiB
JavaScript
Raw Normal View History

/* eslint react/prop-types: "off", react-native/no-inline-styles: "off" */
2024-05-20 11:54:13 +02:00
import Clipboard from '@react-native-clipboard/clipboard';
2024-06-08 18:18:56 +02:00
import React, { forwardRef } from 'react';
2018-12-12 04:33:28 +01:00
import {
ActivityIndicator,
Dimensions,
2024-05-20 11:54:13 +02:00
I18nManager,
2019-01-31 07:52:21 +01:00
InputAccessoryView,
2020-09-09 19:55:13 +02:00
Keyboard,
KeyboardAvoidingView,
2018-12-12 04:33:28 +01:00
Platform,
2020-09-09 19:55:13 +02:00
StyleSheet,
TextInput,
2020-09-09 19:55:13 +02:00
TouchableOpacity,
View,
2018-12-12 04:33:28 +01:00
} from 'react-native';
2024-06-12 18:46:44 +02:00
import { Icon, Text } from '@rneui/themed';
2024-05-20 11:54:13 +02:00
2024-06-08 18:18:56 +02:00
import { useTheme } from './components/themes';
import loc from './loc';
2018-05-12 22:27:34 +02:00
const { height, width } = Dimensions.get('window');
const aspectRatio = height / width;
let isIpad;
if (aspectRatio > 1.6) {
isIpad = false;
} else {
isIpad = true;
}
2018-01-30 23:42:38 +01:00
/**
* TODO: remove this comment once this file gets properly converted to typescript.
*
* @type {React.FC<any>}
*/
export const BlueButtonLink = forwardRef((props, ref) => {
2020-07-15 19:32:59 +02:00
const { colors } = useTheme();
return (
<TouchableOpacity
accessibilityRole="button"
2020-07-15 19:32:59 +02:00
style={{
minHeight: 60,
minWidth: 100,
justifyContent: 'center',
}}
{...props}
ref={ref}
2020-07-15 19:32:59 +02:00
>
<Text style={{ color: colors.foregroundColor, textAlign: 'center', fontSize: 16 }}>{props.title}</Text>
2020-07-15 19:32:59 +02:00
</TouchableOpacity>
);
});
2020-07-15 19:32:59 +02:00
2020-11-30 05:18:54 +01:00
export const BlueCard = props => {
return <View {...props} style={{ padding: 20 }} />;
};
2018-01-30 23:42:38 +01:00
2020-11-22 09:04:04 +01:00
export const BlueText = props => {
2020-07-15 19:32:59 +02:00
const { colors } = useTheme();
const style = StyleSheet.compose({ color: colors.foregroundColor, writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr' }, props.style);
return <Text {...props} style={style} />;
2020-07-15 19:32:59 +02:00
};
2018-01-30 23:42:38 +01:00
2020-11-25 04:01:51 +01:00
export const BlueTextCentered = props => {
const { colors } = useTheme();
return <Text {...props} style={{ color: colors.foregroundColor, textAlign: 'center' }} />;
};
2022-01-28 12:13:53 +01:00
export const BlueFormLabel = props => {
const { colors } = useTheme();
2021-05-22 05:36:34 +02:00
return (
<Text
{...props}
style={{
color: colors.foregroundColor,
fontWeight: '400',
marginHorizontal: 20,
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
}}
/>
);
};
2018-01-30 23:42:38 +01:00
2020-11-30 05:18:54 +01:00
export const BlueFormMultiInput = props => {
const { colors } = useTheme();
2020-11-30 05:18:54 +01:00
return (
<TextInput
multiline
underlineColorAndroid="transparent"
numberOfLines={4}
style={{
paddingHorizontal: 8,
paddingVertical: 16,
flex: 1,
marginTop: 5,
marginHorizontal: 20,
borderColor: colors.formBorder,
borderBottomColor: colors.formBorder,
borderWidth: 1,
borderBottomWidth: 0.5,
borderRadius: 4,
backgroundColor: colors.inputBackgroundColor,
color: colors.foregroundColor,
textAlignVertical: 'top',
}}
autoCorrect={false}
autoCapitalize="none"
spellCheck={false}
{...props}
selectTextOnFocus={false}
keyboardType={Platform.OS === 'android' ? 'visible-password' : 'default'}
/>
);
};
2018-05-06 19:12:14 +02:00
2020-11-30 05:18:54 +01:00
export const BlueSpacing = props => {
return <View {...props} style={{ height: 60 }} />;
};
2018-06-29 00:17:14 +02:00
2020-11-28 04:24:20 +01:00
export const BlueSpacing40 = props => {
return <View {...props} style={{ height: 50 }} />;
};
2018-01-30 23:42:38 +01:00
2018-06-29 00:17:14 +02:00
export class is {
static ipad() {
return isIpad;
}
}
2020-11-28 04:24:20 +01:00
export const BlueSpacing20 = props => {
2021-09-09 13:00:11 +02:00
const { horizontal = false } = props;
return <View {...props} style={{ height: horizontal ? 0 : 20, width: horizontal ? 20 : 0, opacity: 0 }} />;
2020-11-28 04:24:20 +01:00
};
2018-06-25 00:22:46 +02:00
2020-11-28 04:24:20 +01:00
export const BlueSpacing10 = props => {
return <View {...props} style={{ height: 10, opacity: 0 }} />;
};
2019-05-22 14:08:31 +02:00
export const BlueDismissKeyboardInputAccessory = () => {
const { colors } = useTheme();
BlueDismissKeyboardInputAccessory.InputAccessoryViewID = 'BlueDismissKeyboardInputAccessory';
2019-08-29 06:18:32 +02:00
return Platform.OS !== 'ios' ? null : (
<InputAccessoryView nativeID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}>
2019-08-29 06:18:32 +02:00
<View
style={{
backgroundColor: colors.inputBackgroundColor,
height: 44,
flex: 1,
2019-08-29 06:18:32 +02:00
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems: 'center',
}}
>
<BlueButtonLink title={loc.send.input_done} onPress={Keyboard.dismiss} />
2019-08-29 06:18:32 +02:00
</View>
</InputAccessoryView>
);
};
2019-08-29 06:18:32 +02:00
export const BlueDoneAndDismissKeyboardInputAccessory = props => {
const { colors } = useTheme();
BlueDoneAndDismissKeyboardInputAccessory.InputAccessoryViewID = 'BlueDoneAndDismissKeyboardInputAccessory';
const onPasteTapped = async () => {
const clipboard = await Clipboard.getString();
props.onPasteTapped(clipboard);
};
const inputView = (
<View
style={{
backgroundColor: colors.inputBackgroundColor,
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems: 'center',
maxHeight: 44,
}}
>
<BlueButtonLink title={loc.send.input_clear} onPress={props.onClearTapped} />
<BlueButtonLink title={loc.send.input_paste} onPress={onPasteTapped} />
<BlueButtonLink title={loc.send.input_done} onPress={Keyboard.dismiss} />
</View>
);
if (Platform.OS === 'ios') {
return <InputAccessoryView nativeID={BlueDoneAndDismissKeyboardInputAccessory.InputAccessoryViewID}>{inputView}</InputAccessoryView>;
} else {
return <KeyboardAvoidingView>{inputView}</KeyboardAvoidingView>;
2019-08-29 06:18:32 +02:00
}
};
2019-08-29 06:18:32 +02:00
2020-11-30 05:18:54 +01:00
export const BlueLoading = props => {
2020-07-15 19:32:59 +02:00
return (
2021-04-29 16:32:48 +02:00
<View style={{ flex: 1, justifyContent: 'center' }} {...props}>
2020-07-15 19:32:59 +02:00
<ActivityIndicator />
</View>
);
};
2024-04-18 03:33:13 +02:00
export function BlueBigCheckmark({ style = {} }) {
2020-04-28 18:27:35 +02:00
const defaultStyles = {
backgroundColor: '#ccddf9',
width: 120,
height: 120,
borderRadius: 60,
alignSelf: 'center',
justifyContent: 'center',
marginTop: 0,
marginBottom: 0,
};
const mergedStyles = { ...defaultStyles, ...style };
return (
<View style={mergedStyles}>
<Icon name="check" size={50} type="font-awesome" color="#0f5cc0" />
</View>
);
2024-04-29 15:01:46 +02:00
}