To update your ReadStoryScreen component to remove the specific type checks for "header", "subheader", and "image", and instead render the content in Markdown format while maintaining the existing sentence and word interaction functionality, follow these steps:
- Remove Type-Based Rendering in
ContentBlock
- Integrate Markdown Parsing
- Maintain Word Press Functionality
Below is the updated code with detailed explanations for each change.
Step 1: Remove Type-Based Rendering in ContentBlock
First, we'll modify the ContentBlock component to eliminate the type-based conditional rendering. Instead, we'll treat all sentences uniformly and render them as Markdown content.
Updated ContentBlock Component:
const ContentBlock = React.memo(({ sentences, handleWordPress, fontSize, theme, arabicFont, knownWords, handleSentenceButtonPress, selectedSentence }) => {
if (sentences.length === 0) return null;
return (
<View style={styles.paragraphContainer}>
<View style={styles.arabicTextWrapper}>
{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={styles.sentenceButton}
>
<Image
source={require('../../assets/translate.png')}
style={{
width: fontSize * 1.5,
height: fontSize * 1.5,
}}
/>
</TouchableOpacity>
{sentenceIndex < sentences.length - 1 && (
<Text style={[
styles.descriptionArabic,
{
fontSize: fontSize * 1.4,
color: theme.textColor,
fontFamily: arabicFont,
}
]}> </Text>
)}
</React.Fragment>
))}
</View>
</View>
);
});
Changes Made:
- Removed Type Checks: All conditional rendering based on
sentence.type has been removed. Now, every sentence is treated as part of a regular paragraph.
- Consistent Rendering: Each sentence is split into words and rendered using the
Word component, maintaining the word press functionality.
- Sentence Translation Button: The translation button is preserved and placed after each sentence.
Step 2: Integrate Markdown Parsing
To render Markdown content, we'll use the react-native-markdown-display library. This library allows us to parse and display Markdown content while maintaining the ability to wrap words for interaction.
Installation:
First, install the library:
npm install react-native-markdown-display
# or
yarn add react-native-markdown-display
Update ContentBlock to Use Markdown:
We'll modify the ContentBlock to render the content using Markdown component. However, to retain word interaction, we'll need to process the Markdown content and wrap each word with the Word component.
Updated ContentBlock with Markdown Support:
import Markdown from 'react-native-markdown-display';
const ContentBlock = React.memo(({ sentences, handleWordPress, fontSize, theme, arabicFont, knownWords, handleSentenceButtonPress, selectedSentence }) => {
if (sentences.length === 0) return null;
// Combine all sentences into a single Markdown string
const markdownContent = sentences.map(sentence => sentence.content).join(' \n');
// Custom renderer to wrap words with TouchableOpacity
const renderMarkdown = (text) => {
return text.split(' ').map((word, index) => (
<React.Fragment key={index}>
<Word
word={word}
onPress={handleWordPress}
style={[
styles.descriptionArabic,
{
fontSize: fontSize * 1.4,
color: theme.textColor,
fontFamily: arabicFont,
}
]}
isKnown={knownWords.has(word)}
/>
{' '}
</React.Fragment>
));
};
return (
<View style={styles.paragraphContainer}>
<Markdown
style={{
body: {
color: theme.textColor,
fontSize: fontSize * 1.4,
fontFamily: arabicFont,
},
// Add other Markdown styles if needed
}}
onLinkPress={(url) => {
// Handle link presses if necessary
}}
>
{markdownContent}
</Markdown>
{/* Optional: If you want to wrap each word with TouchableOpacity for interaction, you might need a more advanced approach or custom renderer */}
{/* Example: Adding translation button at the end of each sentence */}
{sentences.map((sentence, index) => (
<View key={sentence.id} style={{ flexDirection: 'row', alignItems: 'center' }}>
<Text
style={{
color: theme.textColor,
fontSize: fontSize * 1.4,
fontFamily: arabicFont,
flex: 1,
}}
>
{sentence.content}
</Text>
<TouchableOpacity
onPress={() => handleSentenceButtonPress(sentence.content)}
style={styles.sentenceButton}
>
<Image
source={require('../../assets/translate.png')}
style={{
width: fontSize * 1.5,
height: fontSize * 1.5,
}}
/>
</TouchableOpacity>
</View>
))}
</View>
);
});
Notes:
-
Custom Renderer Limitation: The react-native-markdown-display library doesn't natively support wrapping each word with a TouchableOpacity for interaction. To achieve this, you'd need to implement a custom renderer or preprocess the Markdown content to insert interactive components.
-
Alternative Approach: If wrapping each word with TouchableOpacity is essential, you might consider manually parsing the Markdown and rendering the content accordingly. However, this can become complex and may require a custom solution.
Step 3: Maintain Word Press Functionality
To ensure that word interactions remain functional, we need to process the Markdown content to allow each word to be interactive. Here's an approach using a custom renderer for the react-native-markdown-display library.
Implementing Custom Renderers:
import Markdown, { MarkdownIt } from 'react-native-markdown-display';
import { TouchableOpacity } from 'react-native';
// Initialize MarkdownIt with necessary plugins
const markdownIt = new MarkdownIt();
const ContentBlock = React.memo(({ sentences, handleWordPress, fontSize, theme, arabicFont, knownWords, handleSentenceButtonPress, selectedSentence }) => {
if (sentences.length === 0) return null;
// Combine all sentences into a single Markdown string
const markdownContent = sentences.map(sentence => sentence.content).join(' \n');
// Custom rendering rule for text to wrap words with TouchableOpacity
const rules = {
text: (node, children, parent, styles) => {
const words = node.content.split(' ');
return (
<Text style={styles.text}>
{words.map((word, index) => (
<TouchableOpacity key={index} onPress={() => handleWordPress(word)}>
<Text
style={[
styles.text,
{
fontSize: fontSize * 1.4,
color: theme.textColor,
fontFamily: arabicFont,
backgroundColor: knownWords.has(word) ? 'rgba(0, 255, 0, 0.1)' : 'transparent',
}
]}
>
{word}{' '}
</Text>
</TouchableOpacity>
))}
</Text>
);
},
};
return (
<View style={styles.paragraphContainer}>
<Markdown
style={{
body: {
color: theme.textColor,
fontSize: fontSize * 1.4,
fontFamily: arabicFont,
},
// Add other Markdown styles if needed
}}
rules={rules}
>
{markdownContent}
</Markdown>
{/* Adding translation buttons after each sentence */}
{sentences.map((sentence, index) => (
<View key={sentence.id} style={{ flexDirection: 'row', alignItems: 'center', marginTop: 5 }}>
<TouchableOpacity
onPress={() => handleSentenceButtonPress(sentence.content)}
style={styles.sentenceButton}
>
<Image
source={require('../../assets/translate.png')}
style={{
width: fontSize * 1.5,
height: fontSize * 1.5,
}}
/>
</TouchableOpacity>
</View>
))}
</View>
);
});
Explanation:
-
Custom text Rule: We've defined a custom rendering rule for text nodes. This rule splits the text into words and wraps each word with a TouchableOpacity to handle word presses.
-
Styling Known Words: Known words are highlighted with a background color by checking if the word exists in the knownWords set.
-
Translation Buttons: Translation buttons are added after each sentence to handle sentence-level interactions.
Complete Updated Code
Integrating all the changes, here is the complete updated ReadStoryScreen component:
import React, { useEffect, useState, useRef, useCallback, useMemo } from 'react';
import { View, StyleSheet, Text, FlatList, Image, TouchableOpacity, ActivityIndicator, BackHandler } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import WordExplanationBox from './WordExplanationBox';
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Font from 'expo-font';
import { useThemeAndLanguage } from '../utils/ThemeAndLanguageContext';
import { BottomSheetModal, BottomSheetModalProvider, BottomSheetScrollView } from '@gorhom/bottom-sheet';
import QuizScreen from './QuizScreen';
import { doc, getDoc } from 'firebase/firestore';
import { db } from '../utils/firebase';
import { useFocusEffect } from '@react-navigation/native';
import { useVocabulary } from './VocabularyContext';
import PropTypes from 'prop-types';
import ToggleHeartButton from './heart';
import { CustomTextR, CustomTextB } from '../components/CustomText';
import Markdown from 'react-native-markdown-display';
import MarkdownIt from 'markdown-it';
const ARABIC_FONTS = {
'Scheherazade': require('../../assets/fonts/scheherazade.ttf'),
'Adobe Arabic': require('../../assets/fonts/adobearabic.ttf'),
'Amiri': require('../../assets/fonts/amiri.ttf'),
'Noto Naskh Arabic': require('../../assets/fonts/noto.ttf'),
};
const STORAGE_KEY = '@user_words';
const Word = React.memo(({ word, onPress, style, isKnown }) => (
<TouchableOpacity onPress={() => onPress(word)}>
<Text style={[style, isKnown && styles.knownWord]}>{word}</Text>
</TouchableOpacity>
));
Word.propTypes = {
word: PropTypes.string.isRequired,
onPress: PropTypes.func.isRequired,
style: PropTypes.object,
isKnown: PropTypes.bool,
};
const ContentBlock = React.memo(({ sentences, handleWordPress, fontSize, theme, arabicFont, knownWords, handleSentenceButtonPress, selectedSentence }) => {
if (sentences.length === 0) return null;
// Combine all sentences into a single Markdown string
const markdownContent = sentences.map(sentence => sentence.content).join(' \n');
// Custom renderer rules
const rules = {
text: ({ children, ...props }) => {
const words = props.children.split(' ');
return (
<View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
{words.map((word, index) => (
<TouchableOpacity key={index} onPress={() => handleWordPress(word)}>
<Text
style={[
styles.descriptionArabic,
{
fontSize: fontSize * 1.4,
color: theme.textColor,
fontFamily: arabicFont,
backgroundColor: knownWords.has(word) ? 'rgba(0, 255, 0, 0.1)' : 'transparent',
}
]}
>
{word}{' '}
</Text>
</TouchableOpacity>
))}
</View>
);
},
// You can add more custom rules for bold, italic, etc., if needed
};
return (
<View style={styles.paragraphContainer}>
<Markdown
style={{
body: {
color: theme.textColor,
fontSize: fontSize * 1.4,
fontFamily: arabicFont,
},
}}
rules={rules}
>
{markdownContent}
</Markdown>
{/* Adding translation buttons after each sentence */}
{sentences.map((sentence, index) => (
<View key={sentence.id} style={{ flexDirection: 'row', alignItems: 'center', marginTop: 5 }}>
<TouchableOpacity
onPress={() => handleSentenceButtonPress(sentence.content)}
style={styles.sentenceButton}
>
<Image
source={require('../../assets/translate.png')}
style={{
width: fontSize * 1.5,
height: fontSize * 1.5,
}}
/>
</TouchableOpacity>
</View>
))}
</View>
);
});
ContentBlock.propTypes = {
sentences: PropTypes.arrayOf(PropTypes.shape({
type: PropTypes.string,
content: PropTypes.string,
id: PropTypes.string,
})).isRequired,
handleWordPress: PropTypes.func.isRequired,
fontSize: PropTypes.number.isRequired,
theme: PropTypes.object.isRequired,
arabicFont: PropTypes.string.isRequired,
knownWords: PropTypes.instanceOf(Set).isRequired,
handleSentenceButtonPress: PropTypes.func.isRequired,
selectedSentence: PropTypes.string,
};
export default function ReadStoryScreen({ route, navigation }) {
const { story, storyId } = route.params;
const [fontSize, setFontSize] = useState(20);
const [selectedWord, setSelectedWord] = useState(null);
const [selectedSentence, setSelectedSentence] = useState(null);
const [loading, setLoading] = useState(true);
const [cachedStory, setCachedStory] = useState(null);
const [hasQuiz, setHasQuiz] = useState(false);
const bottomSheetModalRef = useRef(null);
const settingsBottomSheetModalRef = useRef(null);
const quizBottomSheetModalRef = useRef(null);
const { locale, theme, arabicFont, setFontFamily, t } = useThemeAndLanguage();
const [activeModal, setActiveModal] = useState(null);
const [knownWords, setKnownWords] = useState(new Set());
const { vocabulary, isLoggedIn, userId } = useVocabulary();
const increaseFontSize = useCallback(() => setFontSize(prevSize => prevSize + 2), []);
const decreaseFontSize = useCallback(() => setFontSize(prevSize => prevSize - 2), []);
const closeAllModals = useCallback(() => {
bottomSheetModalRef.current?.dismiss();
settingsBottomSheetModalRef.current?.dismiss();
quizBottomSheetModalRef.current?.dismiss();
setActiveModal(null);
}, []);
const openSettingsModal = useCallback(() => {
settingsBottomSheetModalRef.current?.present();
setActiveModal('settings');
}, []);
const openQuizModal = useCallback(() => {
quizBottomSheetModalRef.current?.present();
setActiveModal('quiz');
}, []);
const handleWordPress = useCallback((word) => {
setSelectedWord(word);
setSelectedSentence(null);
bottomSheetModalRef.current?.present();
setActiveModal('word');
}, []);
const handleSentenceButtonPress = useCallback((sentence) => {
setSelectedSentence(sentence);
setSelectedWord(null);
bottomSheetModalRef.current?.present();
setActiveModal('sentence');
}, []);
const loadFonts = useCallback(async () => {
await Font.loadAsync(ARABIC_FONTS);
}, []);
const fetchStoryFromFirestore = useCallback(async (id) => {
const storyDocRef = doc(db, 'stories', id);
const storyDoc = await getDoc(storyDocRef);
return storyDoc.exists() ? { id: storyDoc.id, ...storyDoc.data() } : null;
}, []);
const fetchStory = useCallback(async () => {
try {
let storyData;
if (story) {
storyData = story;
} else if (storyId) {
const cachedData = await AsyncStorage.getItem(`story-${storyId}`);
if (cachedData) {
storyData = JSON.parse(cachedData);
} else {
storyData = await fetchStoryFromFirestore(storyId);
if (storyData) {
await AsyncStorage.setItem(`story-${storyId}`, JSON.stringify(storyData));
}
}
}
if (storyData) {
setCachedStory(storyData);
setHasQuiz(storyData.test_questions && storyData.test_questions.length > 0);
}
} catch (error) {
console.error('Error fetching story:', error);
} finally {
setLoading(false);
}
}, [story, storyId, fetchStoryFromFirestore]);
const fetchKnownWords = useCallback(async () => {
if (!isLoggedIn) {
setKnownWords(new Set());
return;
}
try {
const cachedWords = await AsyncStorage.getItem(STORAGE_KEY);
if (cachedWords) {
const wordsArray = JSON.parse(cachedWords);
setKnownWords(new Set(wordsArray.map(word => word.word)));
}
} catch (error) {
console.error('Error fetching known words:', error);
}
}, [isLoggedIn]);
useEffect(() => {
const initialize = async () => {
await loadFonts();
await fetchStory();
await fetchKnownWords();
};
initialize();
}, [loadFonts, fetchStory, fetchKnownWords]);
useEffect(() => {
if (cachedStory) {
const storyTitle = locale === 'tr' ? cachedStory.storytitleturkish : cachedStory.storytitleenglish;
const truncatedTitle = storyTitle.length > 23 ? `${storyTitle.substring(0, 23)}...` : storyTitle;
navigation.setOptions({
title: truncatedTitle,
headerStyle: { backgroundColor: theme.lighterCardBackgroundColor },
headerTintColor: theme.textColor,
headerTitleStyle: { color: theme.textColor, fontWeight: 'bold' },
headerRight: () => (
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<ToggleHeartButton storyId={cachedStory.id} initialHeartCount={cachedStory.hearts} />
<TouchableOpacity onPress={openSettingsModal} style={styles.fontSizeControl}>
<Ionicons name="settings-outline" size={24} color={theme.textColor} />
</TouchableOpacity>
</View>
),
});
}
}, [navigation, cachedStory, theme, locale, openSettingsModal]);
useFocusEffect(
useCallback(() => {
const onBackPress = () => {
if (activeModal) {
closeAllModals();
return true;
}
return false;
};
BackHandler.addEventListener('hardwareBackPress', onBackPress);
return () => BackHandler.removeEventListener('hardwareBackPress', onBackPress);
}, [activeModal, closeAllModals])
);
// Group sentences into blocks without considering types
const groupSentencesIntoBlocks = useCallback((sentences) => {
// Since we're treating all sentences uniformly, each block can be treated as a single block
return [sentences];
}, []);
const renderBlock = useCallback(({ item: sentences }) => (
<ContentBlock
sentences={sentences}
handleWordPress={handleWordPress}
fontSize={fontSize}
theme={theme}
arabicFont={arabicFont}
knownWords={knownWords}
handleSentenceButtonPress={handleSentenceButtonPress}
selectedSentence={selectedSentence}
/>
), [handleWordPress, fontSize, theme, arabicFont, knownWords, handleSentenceButtonPress, selectedSentence]);
const memoizedBlocks = useMemo(() => {
if (!cachedStory?.sentences) return [];
return groupSentencesIntoBlocks(cachedStory.sentences);
}, [cachedStory, groupSentencesIntoBlocks]);
const keyExtractor = useCallback((item, index) => `block-${index}`, []);
useEffect(() => {
const updatedKnownWords = new Set(vocabulary.map(word => word.word));
setKnownWords(updatedKnownWords);
}, [vocabulary]);
if (loading) {
return (
<View style={[styles.loadingContainer, { backgroundColor: theme.backgroundColorForWordBox }]}>
<ActivityIndicator size="large" color={theme.primaryColor} />
</View>
);
}
if (!cachedStory) {
return (
<View style={[styles.loadingContainer, { backgroundColor: theme.backgroundColorForWordBox }]}>
<Text style={{ color: theme.textColor }}>{t('storyNotFound')}</Text>
</View>
);
}
return (
<BottomSheetModalProvider>
<View style={[styles.container, { backgroundColor: theme.backgroundColorForWordBox }]}>
<FlatList
data={memoizedBlocks}
renderItem={renderBlock}
keyExtractor={keyExtractor}
ListHeaderComponent={() => (
<>
<Image source={{ uri: cachedStory.thumbnail }} style={styles.thumbnail} />
<View style={styles.content}>
<View style={styles.header}>
<Text style={[styles.titleArabic, { color: theme.textColor, fontFamily: arabicFont }]}>{cachedStory.storytitlearabic}</Text>
<CustomTextR style={[styles.titleTurkish, { color: theme.secondaryColor }]}>
{locale === 'tr' ? cachedStory.storytitleturkish : cachedStory.storytitleenglish}
</CustomTextR>
</View>
</View>
</>
)}
initialNumToRender={10}
maxToRenderPerBatch={5}
windowSize={10}
/>
{hasQuiz && (
<TouchableOpacity
style={[styles.quizButton, { backgroundColor: theme.primaryColor }]}
onPress={openQuizModal}
>
<CustomTextR style={styles.quizButtonText}>{t('startQuiz')}</CustomTextR>
</TouchableOpacity>
)}
<BottomSheetModal
ref={bottomSheetModalRef}
index={0}
snapPoints={['45%', '90%']}
handleStyle={{ backgroundColor: theme.backgroundColorForWordBox }}
onDismiss={() => setActiveModal(null)}
>
<BottomSheetScrollView contentContainerStyle={styles.bottomSheetContent}>
<WordExplanationBox
word={selectedWord || selectedSentence}
storyId={cachedStory.id}
onClose={() => bottomSheetModalRef.current?.dismiss()}
/>
</BottomSheetScrollView>
</BottomSheetModal>
<BottomSheetModal
ref={settingsBottomSheetModalRef}
index={0}
snapPoints={['85%']}
handleStyle={{ backgroundColor: theme.backgroundColorForWordBox }}
onDismiss={() => setActiveModal(null)}
>
<BottomSheetScrollView
contentContainerStyle={[
styles.settingsContent,
{ backgroundColor: theme.backgroundColorForWordBox }
]}
>
<View style={styles.exampleCard}>
<Text style={[styles.exampleText, { fontSize: fontSize * 1.4, fontFamily: arabicFont }]}>
(هذا مثال على الكتابة بالعربية)
</Text>
</View>
<View style={styles.fontSizeControls}>
<TouchableOpacity onPress={increaseFontSize} style={styles.fontSizeButton}>
<Ionicons name="add-circle-outline" size={40} color={theme.primaryColor} />
<Text style={styles.fontSizeButtonText}>{t('increaseFontSize')}</Text>
</TouchableOpacity>
<TouchableOpacity onPress={decreaseFontSize} style={styles.fontSizeButton}>
<Ionicons name="remove-circle-outline" size={40} color={theme.primaryColor} />
<Text style={styles.fontSizeButtonText}>{t('decreaseFontSize')}</Text>
</TouchableOpacity>
</View>
<View style={styles.fontOptionsContainer}>
{Object.keys(ARABIC_FONTS).map((font) => (
<TouchableOpacity
key={font}
style={styles.fontOption}
onPress={() => setFontFamily(font)}
>
<Text style={styles.fontOptionText}>{font}</Text>
<Text style={[styles.fontOptionSample, { fontFamily: font }]}>
(اقرأ العربية)
</Text>
</TouchableOpacity>
))}
</View>
</BottomSheetScrollView>
</BottomSheetModal>
{hasQuiz && (
<BottomSheetModal
ref={quizBottomSheetModalRef}
index={0}
snapPoints={['90%']}
handleStyle={{ backgroundColor: theme.backgroundColorForWordBox }}
onDismiss={() => setActiveModal(null)}
>
<QuizScreen
story={cachedStory}
onClose={() => {
quizBottomSheetModalRef.current?.dismiss();
setActiveModal(null);
}}
/>
</BottomSheetModal>
)}
</View>
</BottomSheetModalProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
knownWord: {
backgroundColor: 'rgba(0, 255, 0, 0.1)',
borderRadius: 10,
},
loadingContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
thumbnail: {
width: '100%',
aspectRatio: 1 / 1,
},
content: {
padding: 5,
},
header: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
},
titleArabic: {
fontSize: 26,
},
titleTurkish: {
fontSize: 20,
marginTop: 4,
textAlign: 'center',
},
headerRight: {
flexDirection: 'row',
alignItems: 'center',
marginRight: 10,
},
fontSizeControl: {
marginHorizontal: 5,
},
paragraphContainer: {
flexDirection: 'column',
alignItems: 'flex-start',
marginBottom: 10,
paddingLeft: 10,
paddingRight: 10,
},
arabicTextWrapper: {
flex: 1,
flexDirection: 'row-reverse',
flexWrap: 'wrap',
paddingRight: 15,
},
descriptionArabic: {
padding: 2,
},
selectedSentence: {
backgroundColor: 'rgba(255, 215, 0, 0.3)',
},
settingsContent: {
flexGrow: 1,
paddingHorizontal: 20,
paddingBottom: 20,
alignItems: 'center',
},
exampleCard: {
backgroundColor: 'white',
borderRadius: 10,
padding: 15,
marginVertical: 20,
width: '90%',
alignItems: 'center',
elevation: 4,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 3.84,
},
exampleText: {
textAlign: 'center',
},
fontSizeControls: {
flexDirection: 'row',
justifyContent: 'space-around',
width: '100%',
marginBottom: 20,
},
fontSizeButton: {
alignItems: 'center',
},
fontSizeButtonText: {
marginTop: 5,
fontSize: 12,
color: 'gray',
textAlign: 'center',
},
fontOptionsContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-between',
width: '100%',
},
fontOption: {
width: '48%',
backgroundColor: 'white',
borderRadius: 10,
padding: 10,
marginBottom: 15,
alignItems: 'center',
elevation: 2,
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.22,
shadowRadius: 2.22,
},
fontOptionText: {
fontSize: 16,
marginBottom: 5,
},
fontOptionSample: {
fontSize: 18,
},
quizButton: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
padding: 10,
},
quizButtonText: {
color: 'white',
fontWeight: 'bold',
},
bottomSheetContent: {
flexGrow: 1,
},
sentenceButton: {
padding: 5,
alignItems: 'center',
justifyContent: 'center',
},
});
Important Considerations
-
Markdown Parsing Limitations: The react-native-markdown-display library doesn't natively support wrapping each word with interactive components like TouchableOpacity. The custom renderer provided is a workaround but may not handle all Markdown features seamlessly.
-
Performance: Wrapping each word with a TouchableOpacity can impact performance, especially for long texts. Ensure to test and optimize as needed.
-
Styling: Adjust the styles in the rules and ContentBlock to match your design requirements.
-
Further Enhancements:
- Custom Markdown Features: If you need more advanced Markdown features (e.g., images within text, links), consider extending the custom renderer.
- Caching: Optimize the loading and caching of fonts and Markdown content to improve user experience.
-
Testing: Thoroughly test the updated component to ensure that all functionalities like word presses, sentence translations, and modal interactions work as expected.
Conclusion
By removing the type-based checks and integrating Markdown parsing with custom renderers, you can display the content in a more flexible and readable format while maintaining the interactive functionalities of your application. Adjust and extend the custom renderer as needed to fit your specific requirements.