-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
63 lines (57 loc) · 1.51 KB
/
App.js
File metadata and controls
63 lines (57 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react';
import { View, ScrollView } from 'react-native';
import { layout } from 'styles';
import { Header, LanguageBar, TextEntryAndCTA, RenderResults } from 'views';
import { defineOrTranslate } from 'services/translateService'
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
results: [{
translations: [{
grammar: 'adv',
translation: 'test',
examples: [{
text: 'test 1',
translate: ['hola', 'mundo']
}]
}]
}],
from: 'de',
to: 'en'
}
}
changeLanguages(langPair) {
let [from, to] = langPair.split('-')
this.setState({from, to})
}
whenTranslate(text) {
let {from, to} = this.state
defineOrTranslate(
text,
from,
to,
response => this.setState({results: response}),
error => console.log(error)
)
}
render() {
let {from, to} = this.state
return (
<View style={layout.root}>
<View style={layout.header}>
<Header />
</View>
<View style={layout.menu}>
<LanguageBar defaultPair={[from, to]} onLanguageChange={langPair => this.changeLanguages(langPair)} />
</View>
<TextEntryAndCTA onTranslate={text => this.whenTranslate(text)} />
<View style={layout.textResults}>
<ScrollView>
<RenderResults results={this.state.results} />
</ScrollView>
</View>
</View>
);
}
}