/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
shared/chat/pdf/index.tsx
91 строка
3 KB
chrisnojima
refactor(styles): theme via hooks, no android remount (#29515)
08 авг 2026, 02:24
Не верифицирован
08 авг 2026, 02:24
a41d38e
Код
Авторство
О чём код?
import * as C from '@/constants' import * as Kb from '@/common-adapters' import * as React from 'react' import * as T from '@/constants/types' import {useNavigation} from '@react-navigation/native' import {openLocalPathInSystemFileManagerDesktop} from '@/util/fs-storeless-actions' import {attachmentDownloadMessage, takePDFMessage} from '../conversation/attachment-actions' import {useConversationMessage} from '../conversation/data-hooks' type Props = { conversationIDKey?: T.Chat.ConversationIDKey messageID: T.Chat.MessageID url?: string } const ChatPDF = (props: Props) => { const nativeStyles = useNativeStyles() const {messageID} = props const conversationIDKey = props.conversationIDKey ?? T.Chat.noConversationIDKey const [initialMessage] = React.useState(() => isMobile ? undefined : takePDFMessage(conversationIDKey, messageID) ) const [error, setError] = React.useState('') const loadedMessage = useConversationMessage(conversationIDKey, messageID) const message = loadedMessage?.type === 'attachment' ? loadedMessage : initialMessage const title = message?.title || message?.fileName || 'PDF' const url = props.url ?? message?.fileURL const navigation = useNavigation() React.useEffect(() => { if (isMobile) return navigation.setOptions({title}) }, [navigation, title]) if (!isMobile) { const canDownload = !!message const onDownload = () => { if (message) { attachmentDownloadMessage(conversationIDKey, message) } openLocalPathInSystemFileManagerDesktop(C.downloadFolder) } return ( <> <Kb.Box2 direction="vertical" fullWidth={true} fullHeight={true}> <embed src={url} width="100%" height="100%" /> </Kb.Box2> <Kb.ModalFooter> <Kb.ButtonBar small={true}> <Kb.Button type="Default" label="Download" onClick={onDownload} disabled={!canDownload} /> </Kb.ButtonBar> </Kb.ModalFooter> </> ) } return ( <Kb.Box2 direction="vertical" fullWidth={true} fullHeight={true}> {url && !error ? ( <Kb.WebView originWhitelist={['*']} renderLoading={() => ( <Kb.Box2 direction="vertical" justifyContent="center" style={nativeStyles.progressContainer} fullWidth={true} fullHeight={true} > <Kb.ProgressIndicator white={true} /> </Kb.Box2> )} url={url} pinnedURLMode={true} onError={err => setError(err)} style={nativeStyles.webViewContainer} /> ) : ( <Kb.Text type="BodySmallError">Can't load this file {error}</Kb.Text> )} </Kb.Box2> ) } const useNativeStyles = Kb.Styles.createStyleHook(() => ({ progressContainer: {position: 'absolute'}, webViewContainer: {margin: Kb.Styles.globalMargins.xtiny}, })) export default ChatPDF