|
| 1 | +import React, { useLayoutEffect } from "react"; |
| 2 | +import { FlatList, StyleSheet } from "react-native"; |
| 3 | +import { Body, Card, CardItem, Icon, Row, Text } from "native-base"; |
| 4 | +import { StackNavigationProp } from "@react-navigation/stack"; |
| 5 | +import { RouteProp } from "@react-navigation/native"; |
| 6 | +import Clipboard from "@react-native-community/clipboard"; |
| 7 | + |
| 8 | +import Container from "../../components/Container"; |
| 9 | +import { NavigationButton } from "../../components/NavigationButton"; |
| 10 | +import { SettingsStackParamList } from "./index"; |
| 11 | +import { toast, useGetToastEntries } from "../../utils"; |
| 12 | +import { fontFactorNormalized } from "../../utils/scale"; |
| 13 | + |
| 14 | +import { useTranslation } from "react-i18next"; |
| 15 | +import { namespaces } from "../../i18n/i18n.constants"; |
| 16 | + |
| 17 | + |
| 18 | +export interface ISelectListProps { |
| 19 | + navigation: StackNavigationProp<SettingsStackParamList, "LightningPeers">; |
| 20 | + route: RouteProp<SettingsStackParamList, "LightningPeers">; |
| 21 | +} |
| 22 | + |
| 23 | +export default function({ navigation }: ISelectListProps) { |
| 24 | + const t = useTranslation(namespaces.settings.lightningPeers).t; |
| 25 | + const toastEntries = useGetToastEntries(); |
| 26 | + |
| 27 | + useLayoutEffect(() => { |
| 28 | + navigation.setOptions({ |
| 29 | + headerTitle: t("layout.title"), |
| 30 | + headerShown: true, |
| 31 | + headerRight: () => { |
| 32 | + return ( |
| 33 | + <NavigationButton onPress={onPressCopyAllToasts}> |
| 34 | + <Icon type="MaterialCommunityIcons" name="content-copy" style={{ fontSize: 22 }} /> |
| 35 | + </NavigationButton> |
| 36 | + ) |
| 37 | + } |
| 38 | + }); |
| 39 | + }, [navigation]); |
| 40 | + |
| 41 | + const onCopyToastMessage = (i: number) => { |
| 42 | + console.log(toastEntries); |
| 43 | + Clipboard.setString(toastEntries[i] ?? ""); |
| 44 | + toast("Copied to clipboard"); |
| 45 | + } |
| 46 | + |
| 47 | + const onPressCopyAllToasts = () => { |
| 48 | + Clipboard.setString(toastEntries.join("\n") ?? ""); |
| 49 | + toast("Copied to clipboard"); |
| 50 | + } |
| 51 | + |
| 52 | + return ( |
| 53 | + <Container> |
| 54 | + <FlatList |
| 55 | + contentContainerStyle={{ padding: 14 }} |
| 56 | + initialNumToRender={20} |
| 57 | + data={toastEntries} |
| 58 | + renderItem={({ item: toast, index }) => ( |
| 59 | + <Card style={style.card} key={index}> |
| 60 | + <CardItem> |
| 61 | + <Body> |
| 62 | + <Row style={{ width: "100%" }}> |
| 63 | + <Text style={{marginRight: 28 }}>{toast}</Text> |
| 64 | + <Text style={{ position:"absolute", right: 0 }}> |
| 65 | + <Icon type="MaterialCommunityIcons" name="content-copy" style={style.icon} onPress={() => onCopyToastMessage(index)} /> |
| 66 | + </Text> |
| 67 | + </Row> |
| 68 | + </Body> |
| 69 | + </CardItem> |
| 70 | + </Card> |
| 71 | + )} |
| 72 | + keyExtractor={(toast, i) => toast + i} |
| 73 | + /> |
| 74 | + </Container> |
| 75 | + ) |
| 76 | +} |
| 77 | + |
| 78 | +const style = StyleSheet.create({ |
| 79 | + icon: { |
| 80 | + fontSize: 18 * fontFactorNormalized, |
| 81 | + }, |
| 82 | +}); |
0 commit comments