Created
July 4, 2019 13:36
-
-
Save FreddyPoly/0735154882b4a9685ad9044f282bdb76 to your computer and use it in GitHub Desktop.
[REACT NATIVE] react-native-localize Usage Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react" | |
import { View, Image, ViewStyle, TextStyle, ImageStyle, SafeAreaView } from "react-native" | |
import { NavigationScreenProps } from "react-navigation" | |
import { Text } from "../../components/text" | |
import { Button } from "../../components/button" | |
import { Screen } from "../../components/screen" | |
import { Wallpaper } from "../../components/wallpaper" | |
import { Header } from "../../components/header" | |
import { color, spacing } from "../../theme" | |
import { bowserLogo } from "./" | |
import { ApiStore } from "../../services/api/api-store" | |
import { inject } from "mobx-react"; | |
import { translate } from "../../i18n/" | |
import * as RNLocalize from "react-native-localize" | |
const FULL: ViewStyle = { flex: 1 } | |
const CONTAINER: ViewStyle = { | |
backgroundColor: color.transparent, | |
paddingHorizontal: spacing[4], | |
} | |
const TEXT: TextStyle = { | |
color: color.palette.white, | |
fontFamily: "Montserrat", | |
} | |
const BOLD: TextStyle = { fontWeight: "bold" } | |
const HEADER: TextStyle = { | |
paddingTop: spacing[3], | |
paddingBottom: spacing[4] + spacing[1], | |
paddingHorizontal: 0, | |
} | |
const HEADER_TITLE: TextStyle = { | |
...TEXT, | |
...BOLD, | |
fontSize: 12, | |
lineHeight: 15, | |
textAlign: "center", | |
letterSpacing: 1.5, | |
} | |
const TITLE_WRAPPER: TextStyle = { | |
...TEXT, | |
textAlign: "center", | |
} | |
const TITLE: TextStyle = { | |
...TEXT, | |
...BOLD, | |
fontSize: 28, | |
lineHeight: 38, | |
textAlign: "center", | |
} | |
const ALMOST: TextStyle = { | |
...TEXT, | |
...BOLD, | |
fontSize: 26, | |
fontStyle: "italic", | |
} | |
const BOWSER: ImageStyle = { | |
alignSelf: "center", | |
marginVertical: spacing[5], | |
maxWidth: "100%", | |
} | |
const CONTENT: TextStyle = { | |
...TEXT, | |
color: "#BAB6C8", | |
fontSize: 15, | |
lineHeight: 22, | |
marginBottom: spacing[5], | |
} | |
const CONTINUE: ViewStyle = { | |
paddingVertical: spacing[4], | |
paddingHorizontal: spacing[4], | |
backgroundColor: "#5D2555", | |
} | |
const CONTINUE_TEXT: TextStyle = { | |
...TEXT, | |
...BOLD, | |
fontSize: 13, | |
letterSpacing: 2, | |
} | |
const FOOTER: ViewStyle = { backgroundColor: "#20162D" } | |
const FOOTER_CONTENT: ViewStyle = { | |
paddingVertical: spacing[4], | |
paddingHorizontal: spacing[4], | |
} | |
export interface FirstExampleScreenProps extends NavigationScreenProps<{}> { | |
apiStore: ApiStore, | |
} | |
@inject("apiStore") | |
export class FirstExampleScreen extends React.Component<FirstExampleScreenProps, {}> { | |
nextScreen = () => this.props.navigation.navigate("secondExample") | |
componentWillMount = async () => { | |
const res = await this.props.apiStore.test(); | |
console.log(`RES: ${JSON.stringify(res)}`); | |
} | |
render() { | |
return ( | |
<View style={FULL}> | |
<Wallpaper /> | |
<Screen | |
style={CONTAINER} | |
preset="scroll" | |
backgroundColor={color.transparent}> | |
<Header | |
headerTx="firstExampleScreen.poweredBy" | |
style={HEADER} | |
titleStyle={HEADER_TITLE} | |
/> | |
<Text style={TITLE_WRAPPER}> | |
<Text style={TITLE} text="Your new app, " /> | |
<Text style={ALMOST} text="almost" /> | |
<Text style={TITLE} text="!" /> | |
</Text> | |
<Text style={TITLE} preset="header" tx="firstExampleScreen.readyForLaunch" /> | |
<Image source={bowserLogo} style={BOWSER} /> | |
<Text style={CONTENT}> | |
This probably isn't what your app is going to look like. Unless your designer handed you this screen and, in that case, congrats! You're ready to ship. | |
</Text> | |
<Text style={CONTENT}> | |
Cancel = { JSON.stringify(RNLocalize.getCurrencies()) } | |
</Text> | |
</Screen> | |
<SafeAreaView style={FOOTER}> | |
<View style={FOOTER_CONTENT}> | |
<Button | |
style={CONTINUE} | |
textStyle={CONTINUE_TEXT} | |
tx="firstExampleScreen.continue" | |
onPress={this.nextScreen} | |
/> | |
</View> | |
</SafeAreaView> | |
</View> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment