Skip to content

Commit

Permalink
feat: adjust font size of gurmukhi lines based on gurmukhi_font_size …
Browse files Browse the repository at this point in the history
…flag

PoC for feature flags!
  • Loading branch information
Harjot1Singh committed Jan 16, 2022
1 parent 156cb09 commit 3259581
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions src/screens/Gurbani/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Typography from '../../components/Typography'
import Languages from '../../helpers/languages'
import OS from '../../helpers/os'
import transliterators from '../../helpers/transliterators'
import { useFeatureStatus } from '../../services/feature'
import Colors from '../../themes/colors'
import Fonts from '../../themes/fonts'
import Units from '../../themes/units'
Expand All @@ -17,10 +18,16 @@ const styles = StyleSheet.create( {
...( OS.android && { fontFamily: Fonts.MuktaMahee } ),
lineHeight: Units.Base * Units.GurmukhiLineHeightMultiplier,
},
largeFont: {
fontSize: Units.Base * Units.GurmukhiLatinRatio * 1.2,
},
root: {
...px( 20 ),
paddingTop: Units.Base * Units.LineHeightMultiplier,
},
smallFont: {
fontSize: ( Units.Base * Units.GurmukhiLatinRatio ) / 1.2,
},
text: {
color: Colors.SecondaryText,
},
Expand All @@ -44,33 +51,48 @@ export type LineProps = {
transliterations: ( Languages.English | Languages.Hindi | Languages.Urdu )[],
}

const getGurmukhiFontStyle = ( size: ReturnType<typeof useFeatureStatus> ) => {
if ( size === 'small' ) return styles.smallFont
if ( size === 'large' ) return styles.largeFont

return null
}

/**
* Renders the Gurmukhi, any translations, and transliterates the Gurmukhi.
*/
const Line = ( {
gurmukhi,
translations,
transliterations,
}: LineProps ) => (
<View style={styles.root}>
<Typography style={[ styles.gurbani ]}>{toUnicode( gurmukhi )}</Typography>
}: LineProps ) => {
const fontSizeStyle = getGurmukhiFontStyle( useFeatureStatus( 'gurmukhi_font_size' ) )

return (
<View style={styles.root}>
<Typography style={[ styles.gurbani, fontSizeStyle ]}>{toUnicode( gurmukhi )}</Typography>

{transliterations.map( ( language ) => (
<Typography
key={language}
style={[ styles.text, styles.transliteration ]}
>
{transliterators[ language ]( toUnicode( gurmukhi ) )}
</Typography>
) )}
{transliterations.map( ( language ) => (
<Typography
key={language}
style={[ styles.text, styles.transliteration ]}
>
{transliterators[ language ]( toUnicode( gurmukhi ) )}
</Typography>
) )}

{translations
.filter( ( { translationSourceId } ) => translationSourceId === Languages.English )
.map( ( {
translationSourceId,
translation,
} ) => <Typography key={translationSourceId} style={styles.text}>{translation}</Typography> )}
</View>
)
{translations
.filter( ( { translationSourceId } ) => translationSourceId === Languages.English )
.map( ( { translationSourceId, translation } ) => (
<Typography
key={translationSourceId}
style={styles.text}
>
{translation}
</Typography>
) )}
</View>
)
}

export default Line

0 comments on commit 3259581

Please sign in to comment.