},
subHeaderContainer: {
marginVertical: 10,
backgroundColor: 'rgba(0, 0, 0, 0.03)',
borderRightWidth: 3,
width: '97%',
},
imageStyle: {
width: "90%",
alignSelf: "center", // Ortalamak için bunu ekledik
marginBottom: 10,
aspectRatio: 1 / 1, // Oranı sabit tutmak için ekledik
elevation:1,
borderRadius:15,
},
});
kodumda bazı şeyleri değiştireceksin.
istenilenler:
cümleleleri ayrı ayrı satırlara yazıp çekiyoruz ve her cümlenin yanındaki open butonuna bastığımızda aşağıdan bir bottom sheet açılıyor ve bize manayı söylüyordu. bunu aratık react-native-popover-view kütüphanesiyle yapacağız.
cümleler ayrı ayrı satırlarda gözükmeyecek, bir bütün halinde gözükecek. yani cümlenin bitişinde bu open ioniconu gözükecek ve ona kullanıcı tıkladığında tıkladığı cümlenin çevirisini popoverde görecek.
cümlelelerin satır araları azaltılacak, daha kompakt bir metin görünümü elde edilecek.
aynı şekilde kelimeler için de popver kullanacağız.
bu söylediklerimi yap kodu eksiksiz bir şekilde gönder. kodda gereksiz yerler varsa onları da kaldır ama şu anki mevcut işlevselliği bozma.
bu da popoverin dökümanasyonu: bunu kullanarak güzel bir şey oluştur. ok işareti gözükecek. cümleyse cümleyi, kelimeyse kelimeyi işaret eder bir şekilde olacak.
Usage
Showing popover from an element
For the simplest usage, just pass your Touchable into the from prop. The Popover will automatically be shown when the Touchable is pressed.
import React from 'react';
import Popover from 'react-native-popover-view';
function App() {
return (
<Popover
from={(
Press here to open popover!
)}>
This is the contents of the popover
);
}
Note that if you pass an onPress or ref prop to the Touchable it will be overwritten.
Showing popover from an element (advanced)
For more advanced usage, pass in a function that returns any React element. You control which element the popover anchors on (using the sourceRef) and when the popover will be shown (using the showPopover callback). In this example, the Popover will appear to originate from the text inside the popover, and will only be shown when the Touchable is held down.
import React from 'react';
import Popover from 'react-native-popover-view';
function App() {
return (
<Popover
from={(sourceRef, showPopover) => (
Press here to open popover!
)}>
This is the contents of the popover
);
}
Showing popover from an element (allow manual dismiss)
You can control visibility yourself instead of letting the Popover manage it automatically by using the isVisible and onRequestClose prop. This would allow you to manually dismiss the Popover. onRequestClose is called when the user taps outside the Popover. If you want to force the user to tap a button inside the Popover to dismiss, you could omit onRequestClose and change the state manually.
import React, { useState, useEffect } from 'react';
import Popover from 'react-native-popover-view';
function App() {
const [showPopover, setShowPopover] = useState(false);
return (
<Popover
isVisible={showPopover}
onRequestClose={() => setShowPopover(false)}
from={(
<TouchableOpacity onPress={() => setShowPopover(true)}>
Press here to open popover!
)}>
This popover will be dismissed automatically after 2 seconds
);
}
Showing popover from an element (alternative approach)
If you prefer to let the Popover handle opening from an element but need to close it programmatically, you can also use the exposed method requestClose to close it manually.
import React, { useRef } from 'react';
import Popover from 'react-native-popover-view';
function App() {
const popoverRef = useRef();
return (
<Popover
ref={popoverRef}
from={(
Press here to open popover!
)}>
<TouchableOpacity onPress={() => popoverRef.current.requestClose()}>
Tap to close me
);
}
Showing popover from a reference to an element
If you need even more control (e.g. having the Popover and Touchable in complete different parts of the node hierarchy), you can just pass in a normal ref.
import React, { useRef, useState } from 'react';
import Popover from 'react-native-popover-view';
return (
<>
<TouchableOpacity ref={touchable} onPress={() => setShowPopover(true)}>
Press here to open popover!
<Popover from={touchable} isVisible={showPopover} onRequestClose={() => setShowPopover(false)}>
This is the contents of the popover
</>
);
}
Showing popover from a predetermined position
If you already know the exact location of the place you want the Popover to anchor, you can create a Rect(x, y, width, height) object, and show from that Rect. Note that Rect(x, y, 0, 0) is equivalent to showing from the point (x, y).
import React, { useState } from 'react';
import Popover, { Rect } from 'react-native-popover-view';
function App() {
const [showPopover, setShowPopover] = useState(false);
return (
<>
<TouchableOpacity onPress={() => setShowPopover(true)}>
Press here to open popover!
<Popover from={new Rect(5, 100, 20, 40)} isVisible={showPopover} onRequestClose={() => setShowPopover(false)}>
This is the contents of the popover
</>
);
}
Showing popover without anchor
If you just want the popover to be floating on the screen, not anchored to anything, you can omit the from prop altogether.
import React, { useState } from 'react';
import Popover from 'react-native-popover-view';
function App() {
const [showPopover, setShowPopover] = useState(false);
return (
<>
<TouchableOpacity onPress={() => setShowPopover(true)}>
Press here to open popover!
<Popover isVisible={showPopover} onRequestClose={() => setShowPopover(false)}>
This popover will stay centered on the screen, even when the device is rotated!
</>
);
}
ayrıca sağ üstten açılan settingside bu popover ile yapmanı istiyorum. popover açıkken popover dışında bir yere tıklanıldığında açık olan popoveri kapatsın.
Certainly! Below is the fully modified ReadStoryScreen component that incorporates the react-native-popover-view library to replace the existing BottomSheetModal implementations. The changes include:
Using Popover for Sentence and Word Explanations:
Sentences are rendered as continuous text with an open icon at the end. Tapping the open icon displays a popover with the sentence translation.
Words within sentences are individually wrapped with popovers that display their explanations when tapped.
Compact Sentence Layout:
Reduced line spacing and adjusted styles to make the text appear more compact and seamless.
Settings Popover:
The settings icon in the header now triggers a popover instead of a bottom sheet. Tapping outside the popover will close it automatically.
Code Cleanup:
Removed unnecessary BottomSheetModal imports and related state management to streamline the component.
Removed imports related to BottomSheetModal and BottomSheetModalProvider.
Added Popover from react-native-popover-view.
Word Component:
Each word is wrapped with a Popover that toggles visibility when the word is pressed.
WordExplanationBox is displayed within the popover.
Sentence Component:
Sentences are rendered with words that individually trigger popovers.
An open icon (Ionicons with name "open-outline") is placed at the end of each sentence. Pressing this icon displays the sentence translation in a popover.
Header Right (Settings):
The settings icon in the header is now wrapped with a Popover. When pressed, it displays the settings options (font size controls and font selection).
Tapping outside the popover automatically closes it.
FlatList:
The FlatList now renders sentences with reduced spacing (marginBottom: 4) for a more compact look.
The ListHeaderComponent includes the story thumbnail and titles as before.
Styles:
Adjusted styles such as sentenceContainer, arabicTextWrapper, and openButton to ensure compactness and proper alignment.
Added popoverContent style for consistent popover appearance.
Settings Popover Visibility State:
Managed via settingsPopoverVisible state within the ReadStoryScreen component.
Quiz Modal:
The quiz modal (QuizScreen) remains as a BottomSheetModal, assuming it serves a distinct purpose separate from word/sentence explanations.
BackHandler:
Removed the useFocusEffect that managed the back button since popovers handle their own visibility and closing.
Notes:
Sentence Translation:
It's assumed that each sentenceObj contains a translation field. Ensure that your Firestore data includes this field or adjust the code to fetch translations as needed.
Popover Placement:
The popover for sentence translations is placed at the bottom of the open icon. Adjust the placement prop if a different positioning is desired.
Touchable Areas:
Ensure that the touchable areas around words and the open icon are sufficiently large for user interaction, especially on smaller devices.
Performance:
Using React.memo for Word and Sentence components helps prevent unnecessary re-renders, enhancing performance.
Accessibility:
Consider adding accessibility labels and hints to touchable components for better accessibility support.
This updated implementation provides a more interactive and compact reading experience by utilizing popovers for word and sentence explanations, as well as for accessing settings. Ensure that the react-native-popover-view library is installed and properly linked in your project. If you encounter any issues or have further customization needs, feel free to ask!