Skip to content

Commit 9c03ad8

Browse files
committed
style(example): updating the RootView component
1 parent 5bc5652 commit 9c03ad8

1 file changed

Lines changed: 16 additions & 27 deletions

File tree

example/src/views/RootView.tsx

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import Speech, {
1616
import Button from '../components/Button';
1717
import {SafeAreaView} from 'react-native-safe-area-context';
1818

19-
const isAndroidLowerThan26 =
20-
Platform.OS === 'android' && Platform.Version <= 26;
19+
const isAndroidLowerThan26 = Platform.OS === 'android' && Platform.Version < 26;
2120

2221
const Introduction =
2322
"This high-performance text-to-speech library is built for bare React Native and Expo, compatible with Android and iOS's new architecture (default from React Native 0.76). It enables seamless speech management with start, pause, resume, and stop controls, and provides events for detailed synthesis management.";
@@ -106,24 +105,6 @@ const RootView: React.FC = () => {
106105
await Speech.speak(Introduction);
107106
}, []);
108107

109-
const onStopPress = React.useCallback(async () => {
110-
await Speech.stop();
111-
}, []);
112-
113-
const onResumePress = React.useCallback(async () => {
114-
await Speech.resume();
115-
if (isAndroidLowerThan26) {
116-
setIsPaused(false);
117-
}
118-
}, []);
119-
120-
const onPausePress = React.useCallback(async () => {
121-
await Speech.pause();
122-
if (isAndroidLowerThan26) {
123-
setIsPaused(true);
124-
}
125-
}, []);
126-
127108
const onHighlightedPress = React.useCallback(
128109
({text, start, end}: HighlightedSegmentArgs) =>
129110
Alert.alert(
@@ -147,13 +128,21 @@ const RootView: React.FC = () => {
147128
</View>
148129
<View style={[gs.row, gs.p10]}>
149130
<Button label="Start" disabled={isStarted} onPress={onStartPress} />
150-
<Button label="Stop" disabled={!isStarted} onPress={onStopPress} />
151-
<Button
152-
label="Pause"
153-
onPress={onPausePress}
154-
disabled={isPaused || !isStarted}
155-
/>
156-
<Button label="Resume" disabled={!isPaused} onPress={onResumePress} />
131+
<Button label="Stop" disabled={!isStarted} onPress={Speech.stop} />
132+
{isAndroidLowerThan26 ? null : (
133+
<React.Fragment>
134+
<Button
135+
label="Pause"
136+
onPress={Speech.pause}
137+
disabled={isPaused || !isStarted}
138+
/>
139+
<Button
140+
label="Resume"
141+
disabled={!isPaused}
142+
onPress={Speech.resume}
143+
/>
144+
</React.Fragment>
145+
)}
157146
</View>
158147
</SafeAreaView>
159148
);

0 commit comments

Comments
 (0)