Extract link component and parse all app text for links
This commit is contained in:
+10
-6
@@ -1,15 +1,19 @@
|
||||
import React from 'react'
|
||||
import { Text } from 'react-native'
|
||||
import styles from "../styles"
|
||||
import Link from './link'
|
||||
|
||||
export default function AppText(props) {
|
||||
// we parse for links in case the text contains any
|
||||
return (
|
||||
<Text
|
||||
style={[styles.appText, props.style]}
|
||||
onPress={props.onPress}
|
||||
>
|
||||
{props.children}
|
||||
</Text>
|
||||
<Link>
|
||||
<Text
|
||||
style={[styles.appText, props.style]}
|
||||
onPress={props.onPress}
|
||||
>
|
||||
{props.children}
|
||||
</Text>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import links from '../../i18n/en/links'
|
||||
|
||||
export default function(url) {
|
||||
const link = Object.values(links).find(link => link.url === url)
|
||||
return link ? link.text : url
|
||||
}
|
||||
+3
-7
@@ -2,7 +2,6 @@ import React, { Component } from 'react'
|
||||
import { ScrollView, View, TouchableHighlight, Dimensions } from 'react-native'
|
||||
import { LocalDate, ChronoUnit } from 'js-joda'
|
||||
import Icon from 'react-native-vector-icons/Entypo'
|
||||
import Hyperlink from 'react-native-hyperlink'
|
||||
import { secondaryColor, cycleDayColor, periodColor } from '../styles'
|
||||
import {
|
||||
home as labels,
|
||||
@@ -12,7 +11,6 @@ import {
|
||||
import links from '../i18n/en/links'
|
||||
import cycleModule from '../lib/cycle'
|
||||
import { getFertilityStatusForDay } from '../lib/sympto-adapter'
|
||||
import replace from './helpers/replace-url-with-text'
|
||||
import styles from '../styles'
|
||||
import AppText from './app-text'
|
||||
import DripHomeIcon from '../assets/drip-home-icons'
|
||||
@@ -158,11 +156,9 @@ export default class Home extends Component {
|
||||
}
|
||||
{ isShowingMore &&
|
||||
<View>
|
||||
<Hyperlink linkStyle={styles.link} linkText={replace} linkDefault>
|
||||
<AppText styles={styles.paragraph}>
|
||||
{ `${statusText} ${links.moreAboutNfp.url}` }
|
||||
</AppText>
|
||||
</Hyperlink>
|
||||
<AppText styles={styles.paragraph}>
|
||||
{ `${statusText} ${links.moreAboutNfp.url}` }
|
||||
</AppText>
|
||||
</View>
|
||||
}
|
||||
</HomeElement>
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
import React from 'react'
|
||||
import { ScrollView, View, BackHandler } from 'react-native'
|
||||
import Hyperlink from 'react-native-hyperlink'
|
||||
import AppText from './app-text'
|
||||
import { shared } from '../i18n/en/labels'
|
||||
import settingsLabels from '../i18n/en/settings'
|
||||
import styles,{secondaryColor} from '../styles'
|
||||
import Button from './button'
|
||||
import { saveLicenseFlag } from '../local-storage'
|
||||
import replace from './helpers/replace-url-with-text'
|
||||
|
||||
const labels = settingsLabels.license
|
||||
export default function License({setLicense}) {
|
||||
return (
|
||||
<ScrollView style={styles.licensePage}>
|
||||
<Hyperlink linkStyle={styles.link} linkText={replace} linkDefault>
|
||||
<AppText style={styles.settingsSegmentTitle}>{labels.title}</AppText>
|
||||
<AppText>{labels.text}</AppText>
|
||||
</Hyperlink>
|
||||
<AppText style={styles.settingsSegmentTitle}>{labels.title}</AppText>
|
||||
<AppText>{labels.text}</AppText>
|
||||
<View style={styles.licenseButtons}>
|
||||
<Button
|
||||
style={styles.licenseButton}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import React from 'react'
|
||||
import Hyperlink from 'react-native-hyperlink'
|
||||
import styles from '../styles'
|
||||
import links from '../i18n/en/links'
|
||||
|
||||
export default function Link(props) {
|
||||
return (
|
||||
<Hyperlink
|
||||
linkStyle={styles.link}
|
||||
linkText={replaceUrlWithText}
|
||||
linkDefault
|
||||
>
|
||||
{props.children}
|
||||
</Hyperlink>
|
||||
)
|
||||
}
|
||||
|
||||
function replaceUrlWithText(url) {
|
||||
const link = Object.values(links).find(l => l.url === url)
|
||||
return (link && link.text) || url
|
||||
}
|
||||
@@ -1,21 +1,16 @@
|
||||
import React, { Component } from 'react'
|
||||
import { ScrollView } from 'react-native'
|
||||
import Hyperlink from 'react-native-hyperlink'
|
||||
import AppText from '../app-text'
|
||||
import SettingsSegment from './shared/settings-segment'
|
||||
import styles from '../../styles/index'
|
||||
import labels from '../../i18n/en/settings'
|
||||
import links from '../../i18n/en/links'
|
||||
import replace from '../helpers/replace-url-with-text'
|
||||
|
||||
export default class AboutSection extends Component {
|
||||
render() {
|
||||
return (
|
||||
<ScrollView>
|
||||
<SettingsSegment title={labels.aboutSection.title}>
|
||||
<Hyperlink linkStyle={styles.link} linkText={replace} linkDefault>
|
||||
<AppText>{labels.aboutSection.text}</AppText>
|
||||
</Hyperlink>
|
||||
<AppText>{labels.aboutSection.text}</AppText>
|
||||
</SettingsSegment>
|
||||
<SettingsSegment title={labels.philosophy.title}>
|
||||
<AppText>{labels.philosophy.text}</AppText>
|
||||
@@ -24,9 +19,7 @@ export default class AboutSection extends Component {
|
||||
<AppText>{labels.credits.note}</AppText>
|
||||
</SettingsSegment>
|
||||
<SettingsSegment title={labels.website.title}>
|
||||
<Hyperlink linkStyle={styles.link} linkDefault>
|
||||
<AppText>{links.website.url}</AppText>
|
||||
</Hyperlink>
|
||||
<AppText>{links.website.url}</AppText>
|
||||
</SettingsSegment>
|
||||
<SettingsSegment title={labels.version.title} last>
|
||||
<AppText>{require('../../package.json').version}</AppText>
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
import React, { Component } from 'react'
|
||||
import { View, ScrollView } from 'react-native'
|
||||
import Hyperlink from 'react-native-hyperlink'
|
||||
import AppText from '../app-text'
|
||||
import styles from '../../styles/index'
|
||||
import labels from '../../i18n/en/settings'
|
||||
import replace from '../helpers/replace-url-with-text'
|
||||
|
||||
export default class License extends Component {
|
||||
render() {
|
||||
return (
|
||||
<ScrollView>
|
||||
<View style={styles.settingsSegment}>
|
||||
<Hyperlink linkStyle={styles.link} linkText={replace} linkDefault>
|
||||
<AppText style={styles.settingsSegmentTitle}>{`${labels.license.title} `}</AppText>
|
||||
<AppText>{`${labels.license.text} `}</AppText>
|
||||
</Hyperlink>
|
||||
<AppText style={styles.settingsSegmentTitle}>{`${labels.license.title} `}</AppText>
|
||||
<AppText>{`${labels.license.text} `}</AppText>
|
||||
</View>
|
||||
</ScrollView>
|
||||
)
|
||||
|
||||
@@ -2,7 +2,6 @@ import React, { Component } from 'react'
|
||||
import {
|
||||
ScrollView, View
|
||||
} from 'react-native'
|
||||
import Hyperlink from 'react-native-hyperlink'
|
||||
import styles, { iconStyles } from '../../../styles'
|
||||
import labels from '../../../i18n/en/settings'
|
||||
import AppText from '../../app-text'
|
||||
@@ -10,7 +9,6 @@ import SettingsSegment from '../shared/settings-segment'
|
||||
import TempSlider from './temp-slider'
|
||||
import UseCervixSetting from './use-cervix'
|
||||
import Icon from 'react-native-vector-icons/Entypo'
|
||||
import replaceUrlWithText from '../../helpers/replace-url-with-text'
|
||||
|
||||
export default class Settings extends Component {
|
||||
constructor(props) {
|
||||
@@ -33,9 +31,7 @@ export default class Settings extends Component {
|
||||
<Icon name="info-with-circle" style={iconStyles.infoInHeading}/>
|
||||
<AppText style={styles.settingsSegmentTitle}>{`${labels.preOvu.title} `}</AppText>
|
||||
</View>
|
||||
<Hyperlink linkStyle={styles.link} linkText={replaceUrlWithText} linkDefault>
|
||||
<AppText>{labels.preOvu.note}</AppText>
|
||||
</Hyperlink>
|
||||
<AppText>{labels.preOvu.note}</AppText>
|
||||
</SettingsSegment>
|
||||
</ScrollView>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user