Skip to content

Commit

Permalink
tts
Browse files Browse the repository at this point in the history
  • Loading branch information
hub-bla committed Nov 5, 2022
1 parent 5e8729e commit c09176b
Showing 1 changed file with 150 additions and 107 deletions.
257 changes: 150 additions & 107 deletions components/header.js
Original file line number Diff line number Diff line change
@@ -1,123 +1,166 @@
import react, { useState, useEffect, useContext } from "react";
import react, { useState, useEffect, useContext } from "react"

import { StyleSheet, Text, View, Button, ScrollView, TouchableOpacity, FlatList } from 'react-native';
import {
StyleSheet,
Text,
View,
Button,
ScrollView,
TouchableOpacity,
FlatList,
} from "react-native"

import { AntDesign } from '@expo/vector-icons';
import { AntDesign } from "@expo/vector-icons"

import NoCard from "./noCard";
import Card from "./card";
import TrashCard from "./trashCard";
import NoCard from "./noCard"
import Card from "./card"
import TrashCard from "./trashCard"

import Tts from 'react-native-tts';
import * as Speech from "expo-speech"

import {Context} from "../context/DataContext";
import { Context } from "../context/DataContext"

export default function Header() {
const {sentence, activeSentence, addToSentence, removeFromSentence, removeAll } = useContext(Context)
const [text, setText] = useState(activeSentence.map((item) => item.name).join(' '))
const {
sentence,
activeSentence,
addToSentence,
removeFromSentence,
removeAll,
} = useContext(Context)
const [text, setText] = useState(
activeSentence.map((item) => item.name).join(" ")
)

const [cards, setCards] = useState(activeSentence)
const [cards, setCards] = useState(activeSentence)

useEffect(() => {
setText(activeSentence.map((item) => item.name).join(" "))
setCards(activeSentence)
}, [activeSentence, removeFromSentence])

useEffect(() => {
setText(activeSentence.map((item) => item.name).join(' '))
setCards(activeSentence)
}, [activeSentence, removeFromSentence])
const pressHandler = () => {
console.log("pressed, tu będzie tts")
//Speech.speak("Borek")
Speech.isSpeakingAsync().then((isSpeaking) => {
console.log(isSpeaking)
if (!isSpeaking) {
const toSpeak = "Borek"
Speech.speak("Borek")
}
})
}

const pressHandler = () => {
console.log('pressed, tu będzie tts')
Tts.speak('Hello, world!');
}
const speak = () => {
const thingToSay = "1"
Speech.speak(thingToSay)
}

const renderItem = ({ item }) => (
<>
{item ? <TouchableOpacity onPress={() => {removeFromSentence(item.id)}}><Card text={item.pl}/></TouchableOpacity> : <NoCard />}
</>
);
const renderItem = ({ item }) => (
<>
{item ? (
<TouchableOpacity
onPress={() => {
removeFromSentence(item.id)
}}>
<Card text={item.pl} />
</TouchableOpacity>
) : (
<NoCard />
)}
</>
)

return (
<View style={styles.header}>
<View style={styles.headerTextContent}>
<ScrollView horizontal style={styles.sentenceContener}>
<Text style={styles.sentence}>{sentence}</Text>
</ScrollView>
</View>
<TouchableOpacity onPress={pressHandler}>
<View style={styles.headerButtonContent}>
<View style={styles.headerButton}>
<AntDesign style={styles.icon} name="caretright" size={20} color="black" />
</View>
</View>
</TouchableOpacity>
<View style={styles.cardContener}>
{cards.length > 0 ?
<View style={styles.cardList}>
<TouchableOpacity onPress={removeAll}>
<TrashCard />
</TouchableOpacity>
<FlatList
data={cards}
renderItem={renderItem}
horizontal={true}
keyExtractor={item => item.id}
/></View>
: <NoCard />}

</View>
</View>
);
return (
<View style={styles.header}>
<View style={styles.headerTextContent}>
<ScrollView horizontal style={styles.sentenceContener}>
<Text style={styles.sentence}>{sentence}</Text>
</ScrollView>
</View>
<TouchableOpacity onPress={pressHandler}>
<View style={styles.headerButtonContent}>
<View style={styles.headerButton}>
<AntDesign
style={styles.icon}
name='caretright'
size={20}
color='black'
/>
</View>
</View>
</TouchableOpacity>
<View style={styles.cardContener}>
{cards.length > 0 ? (
<View style={styles.cardList}>
<TouchableOpacity onPress={removeAll}>
<TrashCard />
</TouchableOpacity>
<FlatList
data={cards}
renderItem={renderItem}
horizontal={true}
keyExtractor={(item) => item.id}
/>
</View>
) : (
<NoCard />
)}
</View>
</View>
)
}

const styles = StyleSheet.create({
header: {
height: 250,
backgroundColor: '#A4C3B2',
borderBottomLeftRadius: 20,
borderBottomRightRadius: 20,
},
headerTextContent: {
padding: 30,
paddingBottom: 20,
paddingTop: 45,
marginLeft: 32,
marginRight: 32,
backgroundColor: '#EAF4F4',
borderBottomLeftRadius: 20,
borderBottomRightRadius: 20,
},
sentence: {
fontSize: 20,
color: '#6B9080',
minWidth: "100%",
},
sentenceContener: {
borderColor: '#A4C3B2',
borderStyle: 'solid',
borderBottomWidth: 2,
},
headerButton: {
backgroundColor: '#6B9080',
borderRadius: 8,
height: 25,
width: 200,
alignItems: 'center',
justifyContent: 'center',
},
headerButtonContent: {
marginTop: 15,
alignItems: 'center',
},
icon: {
color: '#EAF4F4',
},
cardContener: {
flexDirection: 'row',
marginTop: 15,
marginLeft: 32,
marginRight: 32,
marginBottom: 15,
},
cardList: {
flexDirection: 'row',
}
});
header: {
height: 250,
backgroundColor: "#A4C3B2",
borderBottomLeftRadius: 20,
borderBottomRightRadius: 20,
},
headerTextContent: {
padding: 30,
paddingBottom: 20,
paddingTop: 45,
marginLeft: 32,
marginRight: 32,
backgroundColor: "#EAF4F4",
borderBottomLeftRadius: 20,
borderBottomRightRadius: 20,
},
sentence: {
fontSize: 20,
color: "#6B9080",
minWidth: "100%",
},
sentenceContener: {
borderColor: "#A4C3B2",
borderStyle: "solid",
borderBottomWidth: 2,
},
headerButton: {
backgroundColor: "#6B9080",
borderRadius: 8,
height: 25,
width: 200,
alignItems: "center",
justifyContent: "center",
},
headerButtonContent: {
marginTop: 15,
alignItems: "center",
},
icon: {
color: "#EAF4F4",
},
cardContener: {
flexDirection: "row",
marginTop: 15,
marginLeft: 32,
marginRight: 32,
marginBottom: 15,
},
cardList: {
flexDirection: "row",
},
})

0 comments on commit c09176b

Please sign in to comment.