From 769ff363525938c91631af19e2ba2aaf2fc0cc4c Mon Sep 17 00:00:00 2001 From: Nyagami Date: Sat, 13 Jan 2024 22:02:30 +0700 Subject: [PATCH] custom js, css modal --- src/components/index.ts | 1 + .../Modals/CustomFileModal.tsx | 130 +++++ .../{ => Modals}/FontPickerModal.tsx | 0 .../Settings/CustomCSSSettings.tsx | 110 +++++ .../Settings/CustomJSSettings.tsx | 93 ++++ .../Settings/DisplaySettings.tsx | 52 ++ .../Settings/GeneralSettings.tsx | 177 +++++++ .../Settings/ReaderThemeSettings.tsx | 174 +++++++ .../SettingsReaderScreen.tsx | 466 ++---------------- 9 files changed, 783 insertions(+), 420 deletions(-) create mode 100644 src/screens/settings/SettingsReaderScreen/Modals/CustomFileModal.tsx rename src/screens/settings/SettingsReaderScreen/{ => Modals}/FontPickerModal.tsx (100%) create mode 100644 src/screens/settings/SettingsReaderScreen/Settings/CustomCSSSettings.tsx create mode 100644 src/screens/settings/SettingsReaderScreen/Settings/CustomJSSettings.tsx create mode 100644 src/screens/settings/SettingsReaderScreen/Settings/DisplaySettings.tsx create mode 100644 src/screens/settings/SettingsReaderScreen/Settings/GeneralSettings.tsx create mode 100644 src/screens/settings/SettingsReaderScreen/Settings/ReaderThemeSettings.tsx diff --git a/src/components/index.ts b/src/components/index.ts index 063eff7c..760fbb08 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -13,3 +13,4 @@ export { default as ColorPreferenceItem } from './ColorPreferenceItem/ColorPrefe export { default as LoadingMoreIndicator } from './LoadingMoreIndicator/LoadingMoreIndicator'; export { Checkbox } from './Checkbox/Checkbox'; export { RadioButton } from './RadioButton/RadioButton'; +export { default as ConfirmationDialog } from './ConfirmationDialog/ConfirmationDialog'; diff --git a/src/screens/settings/SettingsReaderScreen/Modals/CustomFileModal.tsx b/src/screens/settings/SettingsReaderScreen/Modals/CustomFileModal.tsx new file mode 100644 index 00000000..a0d8d6f1 --- /dev/null +++ b/src/screens/settings/SettingsReaderScreen/Modals/CustomFileModal.tsx @@ -0,0 +1,130 @@ +import React, { useState } from 'react'; +import { StyleSheet, Text, View } from 'react-native'; +import { Modal, overlay, TextInput } from 'react-native-paper'; +import { StorageAccessFramework } from 'expo-file-system'; +import * as DocumentPicker from 'expo-document-picker'; + +import { Button } from '@components/index'; + +import { showToast } from '@utils/showToast'; +import { useTheme } from '@hooks/persisted'; +import { getString } from '@strings/translations'; + +interface CustomFileModal { + visible: boolean; + onDismiss: () => void; + defaultValue: string; + onSave: (val: string) => void; + title: string; + mimeType: 'text/css' | 'application/javascript'; + openFileLabel: string; + placeholder?: string; + description?: string; +} + +const CustomFileModal: React.FC = ({ + onDismiss, + visible, + defaultValue, + onSave, + title, + mimeType, + openFileLabel, + placeholder, + description, +}) => { + const theme = useTheme(); + const [text, setText] = useState(''); + + const openDocumentPicker = async () => { + try { + const file = await DocumentPicker.getDocumentAsync({ + copyToCacheDirectory: false, + type: mimeType, + }); + + if (file.type === 'success') { + const content = await StorageAccessFramework.readAsStringAsync( + file.uri, + ); + + onSave(content.trim()); + onDismiss(); + } + } catch (error: any) { + showToast(error.message); + } + }; + + return ( + + + {title} + + {description} + + +