Skip to content

Commit

Permalink
fix missed theme
Browse files Browse the repository at this point in the history
  • Loading branch information
xcarpentier committed Oct 10, 2019
1 parent 3b81c21 commit 0736bc0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
16 changes: 10 additions & 6 deletions __tests__/__snapshots__/CountryPicker.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ Array [
</View>
<View
style={
Object {
"backgroundColor": "white",
"flex": 1,
"flexDirection": "row",
"justifyContent": "space-between",
}
Array [
Object {
"flex": 1,
"flexDirection": "row",
"justifyContent": "space-between",
},
Object {
"backgroundColor": "#ffffff",
},
]
}
>
<RCTScrollView
Expand Down
24 changes: 11 additions & 13 deletions src/CountryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
FlatList,
ScrollView,
TouchableOpacity,
Text,
ListRenderItemInfo,
PixelRatio,
FlatListProps
Expand All @@ -14,15 +13,15 @@ import { useTheme } from './CountryTheme'
import { Country, Omit } from './types'
import { Flag } from './Flag'
import { useContext } from './CountryContext'
import { CountryText } from './CountryText'

const borderBottomWidth = 2 / PixelRatio.get()

const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
backgroundColor: 'white'
justifyContent: 'space-between'
},
letters: {
marginRight: 10,
Expand Down Expand Up @@ -62,7 +61,7 @@ interface LetterProps {
scrollTo(letter: string): void
}
const Letter = ({ letter, scrollTo }: LetterProps) => {
const { fontFamily, fontSize, activeOpacity } = useTheme()
const { fontSize, activeOpacity } = useTheme()
return (
<TouchableOpacity
testID={`letter-${letter}`}
Expand All @@ -71,12 +70,12 @@ const Letter = ({ letter, scrollTo }: LetterProps) => {
{...{ activeOpacity }}
>
<View style={styles.letter}>
<Text
style={[styles.letterText, { fontFamily, fontSize: fontSize! * 0.8 }]}
<CountryText
style={[styles.letterText, { fontSize: fontSize! * 0.8 }]}
allowFontScaling={false}
>
{letter}
</Text>
</CountryText>
</View>
</TouchableOpacity>
)
Expand All @@ -91,7 +90,7 @@ interface CountryItemProps {
onSelect(country: Country): void
}
const CountryItem = (props: CountryItemProps) => {
const { activeOpacity, fontSize, fontFamily, itemHeight } = useTheme()
const { activeOpacity, itemHeight } = useTheme()
const {
country,
onSelect,
Expand Down Expand Up @@ -121,15 +120,14 @@ const CountryItem = (props: CountryItemProps) => {
<View style={[styles.itemCountry, { height: itemHeight }]}>
{withFlag && <Flag {...{ withEmoji, countryCode: country.cca2 }} />}
<View style={styles.itemCountryName}>
<Text
style={{ fontFamily, fontSize }}
<CountryText
allowFontScaling={false}
numberOfLines={2}
ellipsizeMode="tail"
>
{country.name}
{extraContent.length > 0 && ` (${extraContent.join(', ')})`}
</Text>
</CountryText>
</View>
</View>
</TouchableOpacity>
Expand Down Expand Up @@ -182,7 +180,7 @@ export const CountryList = (props: CountryListProps) => {
} = props
const flatListRef = useRef<FlatList<Country>>(null)
const [letter, setLetter] = useState<string>('')
const { itemHeight } = useTheme()
const { itemHeight, backgroundColor } = useTheme()
const indexLetter = data
.map((country: Country) => (country.name as string).substr(0, 1))
.join('')
Expand Down Expand Up @@ -211,7 +209,7 @@ export const CountryList = (props: CountryListProps) => {
}, [filterFocus])
const { search, getLetters } = useContext()
return (
<View style={styles.container}>
<View style={[styles.container, { backgroundColor }]}>
<FlatList
onScrollToIndexFailed
ref={flatListRef}
Expand Down
13 changes: 13 additions & 0 deletions src/CountryText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { ReactNode } from 'react'
import { TextProps, Text } from 'react-native'
import { useTheme } from './CountryTheme'

export const CountryText = (props: TextProps & { children: ReactNode }) => {
const { fontFamily, fontSize, onBackgroundTextColor } = useTheme()
return (
<Text
{...props}
style={{ fontFamily, fontSize, color: onBackgroundTextColor }}
/>
)
}
2 changes: 1 addition & 1 deletion src/CountryTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const DEFAULT_THEME = {
web: 'Arial'
}),
filterPlaceholderTextColor: '#aaa',
activeOpacity: 0.7,
activeOpacity: 0.5,
itemHeight: getHeightPercent(7)
}
export type Theme = Partial<typeof DEFAULT_THEME>
Expand Down
1 change: 1 addition & 0 deletions src/Flag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const ImageFlag = memo(({ countryCode }: FlagType) => {

const EmojiFlag = memo(({ countryCode }: FlagType) => {
const { getEmojiFlag } = useContext()

return (
<Text style={styles.emojiFlag} allowFontScaling={false}>
<Emoji name={getEmojiFlag(countryCode)} />
Expand Down
19 changes: 9 additions & 10 deletions src/FlagButton.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React, { memo } from 'react'
import {
TouchableOpacity,
StyleSheet,
View,
Text,
Platform
} from 'react-native'
import { TouchableOpacity, StyleSheet, View, Platform } from 'react-native'
import { CountryCode } from './types'
import { Flag } from './Flag'
import { useContext } from './CountryContext'
import { getCountryCallingCode } from './CountryService'
import { CountryText } from './CountryText'

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -57,13 +52,17 @@ const FlagWithSomething = memo(
<View style={styles.flagWithSomethingContainer}>
<Flag {...{ withEmoji, countryCode }} />
{countryName ? (
<Text style={styles.something}>{countryName + ' '}</Text>
<CountryText style={[styles.something]}>
{countryName + ' '}
</CountryText>
) : null}
{currency ? (
<Text style={styles.something}>{`(${currency}) `}</Text>
<CountryText style={styles.something}>{`(${currency}) `}</CountryText>
) : null}
{callingCode ? (
<Text style={styles.something}>{`+${callingCode}`}</Text>
<CountryText
style={styles.something}
>{`+${callingCode}`}</CountryText>
) : null}
</View>
)
Expand Down

0 comments on commit 0736bc0

Please sign in to comment.