const ContentBlock = React.memo(({ sentences, handleWordPress, fontSize, theme,…
- User
const ContentBlock = React.memo(({ sentences, handleWordPress, fontSize, theme, arabicFont, knownWords, handleSentenceButtonPress, selectedSentence }) => { if (sentences.length === 0) return null;
if (sentences[0].type === 'image') { return ( <Image source={{ uri: sentences[0].content }} style={[styles.imageStyle]} /> ); }
if (sentences[0].type === 'header' || sentences[0].type === 'subheader') { const isHeader = sentences[0].type === 'header'; return ( <View style={[ styles.sentenceContainer, selectedSentence === sentences[0].content && styles.selectedSentence, isHeader ? styles.headerContainer : styles.subHeaderContainer, { borderRightColor: isHeader ? theme.primaryColor : theme.secondaryColor } ]}> <TouchableOpacity onPress={() => handleSentenceButtonPress(sentences[0].content)}> <><Image source={require('../../assets/translate.png')} style={{ width: fontSize * 1.5, height: fontSize * 1.5, }} /></> {sentences[0].content.split(' ').map((word, wordIndex) => ( <Word key={
${sentences[0].id}-${wordIndex}} word={word} onPress={handleWordPress} style={[ styles.descriptionArabic, { fontSize: fontSize * (isHeader ? 1.6 : 1.4), color: theme.textColor, fontFamily: arabicFont, } ]} isKnown={knownWords.has(word)} /> ))} ); }// Normal paragraphs - all sentences in one wrapper return ( {sentences.map((sentence, sentenceIndex) => ( <React.Fragment key={sentence.id}> {sentence.content.split(' ').map((word, wordIndex) => ( <Word key={
${sentence.id}-${wordIndex}} word={word} onPress={handleWordPress} style={[ styles.descriptionArabic, { fontSize: fontSize * 1.4, color: theme.textColor, fontFamily: arabicFont, } ]} isKnown={knownWords.has(word)} /> ))} <TouchableOpacity onPress={() => handleSentenceButtonPress(sentence.content)} style={[ { padding:5, alignItems: 'center', justifyContent: 'center' } ]}<Image source={require('../../assets/translate.png')} style={{ width: fontSize * 1.5, height: fontSize * 1.5, }} /> {sentenceIndex < sentences.length - 1 && ( <Text style={[ styles.descriptionArabic, { fontSize: fontSize * 1.4, color: theme.textColor, fontFamily: arabicFont, } ]}> )} </React.Fragment> ))} ); });
bu kod bloğunu incele. burada header subheader image gibi type kontrolleri yapıyoruz. bunu tamamen kaldır. ve yerine react-native-marked kütüphanesini kullanarak markdown karakterlerini işleyeceğiz. bu arada cümlelerin tıklanılabilirliği ve kelimelerin tıklanılabilirliği kesinlikle bozulmayacak. şimdi sana react-native-marked dökümantasyonunu atıyorum:
import React from "react"; import Markdown from "react-native-marked";
function App() { return ( <Markdown value={markdownString} flatListProps={{ initialNumToRender: 8, contentContainerStyle: { padding: 16 } }} styles={{ strong: { color: "red" }, em: { color: "green" } }} /> ); }
const markdownString = ` Markdown Quick Reference
This guide is a very brief overview, with examples, of the syntax that supports. It is itself written in Markdown and you can copy the samples over to the left-hand pane for experimentation. It's shown as and not .
- Assistant