Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Allow style arrays in Text HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Laco committed Sep 7, 2018
1 parent 2d3c26c commit d2c0941
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ node_modules
testgrounds
IntegrationTest
integration_test
ios/Pods
2 changes: 1 addition & 1 deletion boilerplate/src/views/shared/text/text.props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface TextProps extends TextProperties {
/**
* An optional style override useful for padding & margin.
*/
style?: TextStyle
style?: TextStyle | TextStyle[]

/**
* One of the different types of text presets.
Expand Down
9 changes: 8 additions & 1 deletion boilerplate/src/views/shared/text/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Text as ReactNativeText } from "react-native"
import { presets } from "./text.presets"
import { TextProps } from "./text.props"
import { translate } from "../../../i18n"
import { mergeWith, concat } from "ramda"

/**
* For your text displaying needs.
Expand All @@ -19,7 +20,13 @@ export function Text(props: TextProps) {

// assemble the style
const presetToUse = presets[preset] || presets.default
const style = { ...presetToUse, ...styleOverride }
let style
if (Array.isArray(styleOverride)) {
style = mergeWith(concat, ...presetToUse, styleOverride)
} else {
style = { ...presetToUse, ...styleOverride }
}


return (
<ReactNativeText {...rest} style={style}>
Expand Down

0 comments on commit d2c0941

Please sign in to comment.