From 9e57594268bf69224bf6e8fc50e87827e7d1c135 Mon Sep 17 00:00:00 2001 From: Yauhen Date: Tue, 30 Apr 2019 13:35:33 +0300 Subject: [PATCH] feat(ui): props for inline styling add (#379) --- .../bottomNavigation.component.tsx | 5 + .../bottomNavigation.spec.tsx | 16 +- .../bottomNavigation.spec.tsx.snap | 148 +++++++++++- .../bottomNavigationTab.component.tsx | 6 + .../ui/checkbox/checkbox.component.tsx | 11 +- src/framework/ui/checkbox/checkbox.spec.tsx | 1 + .../ui/checkbox/checkbox.spec.tsx.snap | 10 +- src/framework/ui/input/input.component.tsx | 29 ++- src/framework/ui/input/input.spec.tsx | 26 +++ src/framework/ui/input/input.spec.tsx.snap | 218 ++++++++++++++++++ src/framework/ui/list/list.spec.tsx | 27 ++- src/framework/ui/list/list.spec.tsx.snap | 213 ++++++++++++++++- src/framework/ui/list/listItem.component.tsx | 8 + .../ui/overflowMenu/overflowMenu.spec.tsx | 1 + .../overflowMenu/overflowMenu.spec.tsx.snap | 20 ++ .../overflowMenuItem.component.tsx | 7 +- src/framework/ui/radio/radio.component.tsx | 12 +- src/framework/ui/radio/radio.spec.tsx | 10 + src/framework/ui/radio/radio.spec.tsx.snap | 192 +++++++++++++++ src/framework/ui/tab/tab.component.tsx | 10 +- src/framework/ui/tab/tab.spec.tsx | 16 ++ src/framework/ui/tab/tab.spec.tsx.snap | 145 ++++++++++++ src/framework/ui/tab/tabBar.component.tsx | 5 + src/framework/ui/tab/tabView.component.tsx | 13 +- .../ui/tooltip/tooltip.component.tsx | 5 + .../topNavigation/topNavigation.component.tsx | 15 +- .../ui/topNavigation/topNavigation.spec.tsx | 15 ++ .../topNavigation/topNavigation.spec.tsx.snap | 188 +++++++++++++++ .../ui/screen/bottomNavigation.component.tsx | 6 + .../src/ui/screen/overflowMenu.component.tsx | 3 +- .../src/ui/screen/tooltip.component.tsx | 13 +- 31 files changed, 1350 insertions(+), 44 deletions(-) diff --git a/src/framework/ui/bottomNavigation/bottomNavigation.component.tsx b/src/framework/ui/bottomNavigation/bottomNavigation.component.tsx index b1e9ce509..9a6b0b59a 100644 --- a/src/framework/ui/bottomNavigation/bottomNavigation.component.tsx +++ b/src/framework/ui/bottomNavigation/bottomNavigation.component.tsx @@ -4,6 +4,8 @@ import { View, ViewProps, StyleSheet, + StyleProp, + ViewStyle, } from 'react-native'; import { StyledComponentProps, @@ -20,6 +22,7 @@ type ChildElement = React.ReactElement; interface TabNavigatorProps { children: ChildElement | ChildElement[]; selectedIndex?: number; + indicatorStyle?: StyleProp; onSelect?: (index: number) => void; } @@ -34,6 +37,7 @@ export class BottomNavigation extends React.Component { }; private getComponentStyle = (style: StyleType): StyleType => { + const { indicatorStyle } = this.props; const { indicatorHeight, indicatorBackgroundColor, ...containerStyle } = style; return { @@ -44,6 +48,7 @@ export class BottomNavigation extends React.Component { indicator: { height: indicatorHeight, backgroundColor: indicatorBackgroundColor, + ...StyleSheet.flatten(indicatorStyle), ...styles.indicator, }, }; diff --git a/src/framework/ui/bottomNavigation/bottomNavigation.spec.tsx b/src/framework/ui/bottomNavigation/bottomNavigation.spec.tsx index 02035af5d..570343204 100644 --- a/src/framework/ui/bottomNavigation/bottomNavigation.spec.tsx +++ b/src/framework/ui/bottomNavigation/bottomNavigation.spec.tsx @@ -100,6 +100,19 @@ describe('@bottom-navigation-tab: component checks', () => { expect(output).toMatchSnapshot(); }); + it('* text (styled)', () => { + const component: RenderAPI = render( + , + ); + + const { output } = shallow(component.getByType(BottomNavigatorTabComponent)); + + expect(output).toMatchSnapshot(); + }); + }); describe('@bottom-navigation: component checks', () => { @@ -133,8 +146,9 @@ describe('@bottom-navigation: component checks', () => { }); it('* with routes', () => { + const indicatorStyle: StyleType = { backgroundColor: 'red' }; const component: RenderAPI = render( - + `; +exports[`@bottom-navigation-tab: component checks * text (styled) 1`] = ` + + + Test + + +`; + exports[`@bottom-navigation-tab: component checks * text/selected 1`] = ` ; icon?: (style: StyleType) => React.ReactElement; selected?: boolean; onSelect?: (selected: boolean) => void; @@ -32,6 +35,7 @@ export class BottomNavigationTab extends React.Component { }; private getComponentStyle = (source: StyleType): StyleType => { + const { style, titleStyle } = this.props; const { iconWidth, iconHeight, @@ -48,6 +52,7 @@ export class BottomNavigationTab extends React.Component { return { container: { ...containerStyle, + ...StyleSheet.flatten(style), ...styles.container, }, icon: { @@ -63,6 +68,7 @@ export class BottomNavigationTab extends React.Component { lineHeight: textLineHeight, fontWeight: textFontWeight, color: textColor, + ...StyleSheet.flatten(titleStyle), ...styles.text, }, }; diff --git a/src/framework/ui/checkbox/checkbox.component.tsx b/src/framework/ui/checkbox/checkbox.component.tsx index 532f64403..418231ad3 100644 --- a/src/framework/ui/checkbox/checkbox.component.tsx +++ b/src/framework/ui/checkbox/checkbox.component.tsx @@ -14,17 +14,15 @@ import { styled, StyledComponentProps, StyleType, - allWithRest, } from '@kitten/theme'; import { Props as TextProps, Text as TextComponent, } from '../text/text.component'; import { CheckMark } from '../drawable'; -import { TextStyleProps } from '../common/props'; interface CheckBoxProps { - style?: StyleProp; + textStyle?: StyleProp; text?: string; checked?: boolean; indeterminate?: boolean; @@ -66,8 +64,7 @@ export class CheckBox extends React.Component { }; private getComponentStyle = (style: StyleType): StyleType => { - const derivedStyle: TextStyle = StyleSheet.flatten(this.props.style); - const { rest: derivedContainerStyle, ...derivedTextStyle } = allWithRest(derivedStyle, TextStyleProps); + const { style: containerStyle, textStyle } = this.props; const { textMarginHorizontal, @@ -88,7 +85,7 @@ export class CheckBox extends React.Component { return { container: { - ...derivedContainerStyle, + ...StyleSheet.flatten(containerStyle), ...styles.container, }, highlightContainer: styles.highlightContainer, @@ -103,7 +100,7 @@ export class CheckBox extends React.Component { fontWeight: textFontWeight, lineHeight: textLineHeight, ...styles.text, - ...derivedTextStyle, + ...StyleSheet.flatten(textStyle), }, icon: { width: iconWidth, diff --git a/src/framework/ui/checkbox/checkbox.spec.tsx b/src/framework/ui/checkbox/checkbox.spec.tsx index f93b4c005..554ae9103 100644 --- a/src/framework/ui/checkbox/checkbox.spec.tsx +++ b/src/framework/ui/checkbox/checkbox.spec.tsx @@ -84,6 +84,7 @@ describe('@checkbox matches snapshots', () => { const component: RenderAPI = renderComponent({ checked: true, text: text, + textStyle: { fontSize: 18, color: 'red' }, }); const { output } = shallow(component.getByType(CheckBoxComponent)); expect(component.getByType(TextComponent).props.children).toBe(text); diff --git a/src/framework/ui/checkbox/checkbox.spec.tsx.snap b/src/framework/ui/checkbox/checkbox.spec.tsx.snap index 3f9f17cad..94811b85b 100644 --- a/src/framework/ui/checkbox/checkbox.spec.tsx.snap +++ b/src/framework/ui/checkbox/checkbox.spec.tsx.snap @@ -765,6 +765,12 @@ exports[`@checkbox matches snapshots * with text 1`] = ` "width": 24, } } + textStyle={ + Object { + "color": "red", + "fontSize": 18, + } + } theme={ Object { "blue-dark": "#2541CC", @@ -889,8 +895,8 @@ exports[`@checkbox matches snapshots * with text 1`] = ` ; type TextElement = React.ReactElement; @@ -38,6 +36,9 @@ interface InputProps { caption?: string; captionIcon?: IconProp; icon?: IconProp; + textStyle?: StyleProp; + labelStyle?: StyleProp; + captionTextStyle?: StyleProp; } export type Props = InputProps & StyledComponentProps & TextInputProps; @@ -65,9 +66,17 @@ export class Input extends React.Component { }; private getComponentStyle = (style: StyleType): StyleType => { - const derivedStyle: TextStyle = StyleSheet.flatten(this.props.style); - const { rest: containerStyle, ...derivedTextStyle } = allWithRest(derivedStyle, TextStyleProps); - const { rest: inputContainerStyle, ...derivedContainerStyle } = allWithRest(containerStyle, FlexStyleProps); + const { + style: derivedContainerStyle, + textStyle, + labelStyle, + captionTextStyle, + } = this.props; + + const { + rest: inputContainerStyle, + ...containerStyle + } = allWithRest(StyleSheet.flatten(derivedContainerStyle), FlexStyleProps); const { textMarginHorizontal, @@ -98,7 +107,7 @@ export class Input extends React.Component { return { container: { ...styles.container, - ...derivedContainerStyle, + ...containerStyle, }, inputContainer: { ...containerParameters, @@ -114,7 +123,7 @@ export class Input extends React.Component { fontSize: textFontSize, lineHeight: textLineHeight, color: textColor, - ...derivedTextStyle, + ...StyleSheet.flatten(textStyle), ...styles.text, }, icon: { @@ -130,6 +139,7 @@ export class Input extends React.Component { lineHeight: labelLineHeight, marginBottom: labelMarginBottom, fontWeight: labelFontWeight, + ...StyleSheet.flatten(labelStyle), ...styles.label, }, captionIcon: { @@ -144,6 +154,7 @@ export class Input extends React.Component { fontWeight: captionTextFontWeight, lineHeight: captionTextLineHeight, color: captionTextColor, + ...StyleSheet.flatten(captionTextStyle), ...styles.captionLabel, }, }; diff --git a/src/framework/ui/input/input.spec.tsx b/src/framework/ui/input/input.spec.tsx index 9d68e1662..90f0240b3 100644 --- a/src/framework/ui/input/input.spec.tsx +++ b/src/framework/ui/input/input.spec.tsx @@ -101,6 +101,32 @@ describe('@input: matches snapshot', () => { expect(output).toMatchSnapshot(); }); + it('* text styled', () => { + const captionIcon = (style: StyleType): React.ReactElement => { + return ( + + ); + }; + const label: string = 'Label'; + const caption: string = 'Caption Text'; + + const component: RenderAPI = renderComponent({ + label, + caption, + captionIcon, + textStyle: { fontSize: 24, lineHeight: 26 }, + labelStyle: { color: 'blue' }, + captionTextStyle: { letterSpacing: 8, fontFamily: 'opensans-bold' }, + }); + + const { output } = shallow(component.getByType(InputComponent)); + + expect(output).toMatchSnapshot(); + }); + }); }); diff --git a/src/framework/ui/input/input.spec.tsx.snap b/src/framework/ui/input/input.spec.tsx.snap index b156078f3..427b379ca 100644 --- a/src/framework/ui/input/input.spec.tsx.snap +++ b/src/framework/ui/input/input.spec.tsx.snap @@ -372,6 +372,224 @@ exports[`@input: matches snapshot * appearance * label + caption 1`] = ` `; +exports[`@input: matches snapshot * appearance * text styled 1`] = ` + + + Label + + + + + + + + Caption Text + + + +`; + exports[`@input: matches snapshot * interaction * stateless 1`] = ` { it('* description', () => { const item = () => { return ( - + + ); + }; + + const component: RenderAPI = render( + , + ); + + const items: ReactTestInstance[] = component.getAllByType(ListItemComponent); + const { output } = shallow(items[0]); + + expect(output).toMatchSnapshot(); + }); + + it('* text styles', () => { + const item = () => { + return ( + ); }; diff --git a/src/framework/ui/list/list.spec.tsx.snap b/src/framework/ui/list/list.spec.tsx.snap index fca0eb634..0f4b6206c 100644 --- a/src/framework/ui/list/list.spec.tsx.snap +++ b/src/framework/ui/list/list.spec.tsx.snap @@ -4,6 +4,7 @@ exports[`@list-item: template matches snapshot * description 1`] = ` + + Description + + + +`; + +exports[`@list-item: template matches snapshot * text styles 1`] = ` + + Title + + Description + `; diff --git a/src/framework/ui/list/listItem.component.tsx b/src/framework/ui/list/listItem.component.tsx index c2b8d9785..b5b2391e8 100644 --- a/src/framework/ui/list/listItem.component.tsx +++ b/src/framework/ui/list/listItem.component.tsx @@ -7,6 +7,8 @@ import { ImageProps, GestureResponderEvent, StyleSheet, + StyleProp, + TextStyle, } from 'react-native'; import { styled, @@ -32,12 +34,14 @@ interface TemplateBaseProps { interface TemplateTitleProps extends Partial { title: string; + titleStyle?: StyleProp; description?: string; } interface TemplateDescriptionProps extends Partial { title?: string; description: string; + descriptionStyle?: StyleProp; } interface CustomContentProps { @@ -83,6 +87,8 @@ export class ListItem extends React.Component { }; private getComponentStyle = (source: StyleType): StyleType => { + // @ts-ignore: will be not executed if `titleStyle` and `descriptionStyle` properties are provided + const { titleStyle, descriptionStyle } = this.props; const { iconWidth, iconHeight, @@ -119,6 +125,7 @@ export class ListItem extends React.Component { lineHeight: titleLineHeight, fontWeight: titleFontWeight, color: titleColor, + ...StyleSheet.flatten(titleStyle), ...styles.title, }, description: { @@ -126,6 +133,7 @@ export class ListItem extends React.Component { fontSize: descriptionFontSize, lineHeight: descriptionLineHeight, marginHorizontal: descriptionMarginHorizontal, + ...StyleSheet.flatten(descriptionStyle), ...styles.description, }, accessory: { diff --git a/src/framework/ui/overflowMenu/overflowMenu.spec.tsx b/src/framework/ui/overflowMenu/overflowMenu.spec.tsx index deeecc3a0..451b60720 100644 --- a/src/framework/ui/overflowMenu/overflowMenu.spec.tsx +++ b/src/framework/ui/overflowMenu/overflowMenu.spec.tsx @@ -66,6 +66,7 @@ const iconSource: ImageSourcePropType = { uri: 'https://akveo.github.io/eva-icon const menuItems: OverflowMenuItemType[] = [ { text: 'Menu Item 1', + textStyle: { fontSize: 24, color: 'blue' }, icon: icon, }, { diff --git a/src/framework/ui/overflowMenu/overflowMenu.spec.tsx.snap b/src/framework/ui/overflowMenu/overflowMenu.spec.tsx.snap index f48835e65..9cb4a90aa 100644 --- a/src/framework/ui/overflowMenu/overflowMenu.spec.tsx.snap +++ b/src/framework/ui/overflowMenu/overflowMenu.spec.tsx.snap @@ -21,6 +21,12 @@ exports[`@overflow-menu: component checks * component renders properly 1`] = ` ] } text="Menu Item 1" + textStyle={ + Object { + "color": "blue", + "fontSize": 24, + } + } /> } @@ -246,6 +262,10 @@ exports[`@overflow-menu: component checks * single menu-item 1`] = ` Object { "icon": [Function], "text": "Menu Item 1", + "textStyle": Object { + "color": "blue", + "fontSize": 24, + }, }, ] } diff --git a/src/framework/ui/overflowMenu/overflowMenuItem.component.tsx b/src/framework/ui/overflowMenu/overflowMenuItem.component.tsx index a7827bc95..1e144179e 100644 --- a/src/framework/ui/overflowMenu/overflowMenuItem.component.tsx +++ b/src/framework/ui/overflowMenu/overflowMenuItem.component.tsx @@ -4,6 +4,8 @@ import { GestureResponderEvent, StyleSheet, ImageProps, + StyleProp, + TextStyle, } from 'react-native'; import { StyledComponentProps, @@ -20,6 +22,7 @@ import { TouchableOpacityIndexedProps } from '../common/type'; export interface OverflowMenuItemType { icon?: (style: StyleType) => React.ReactElement; text: React.ReactText; + textStyle?: StyleProp; disabled?: boolean; index?: number; } @@ -61,6 +64,7 @@ export class OverflowMenuItem extends React.Component { }; private getComponentStyle = (style: StyleType): StyleType => { + const { textStyle } = this.props; const { textMarginHorizontal, textFontSize, @@ -82,10 +86,11 @@ export class OverflowMenuItem extends React.Component { }, text: { marginHorizontal: textMarginHorizontal, - fontSize: style.textFontSize, + fontSize: textFontSize, lineHeight: textLineHeight, fontWeight: textFontWeight, color: textColor, + ...StyleSheet.flatten(textStyle), }, icon: { width: iconWidth, diff --git a/src/framework/ui/radio/radio.component.tsx b/src/framework/ui/radio/radio.component.tsx index 6c707c70a..985e4fa55 100644 --- a/src/framework/ui/radio/radio.component.tsx +++ b/src/framework/ui/radio/radio.component.tsx @@ -13,16 +13,14 @@ import { StyledComponentProps, StyleType, Interaction, - allWithRest, } from '@kitten/theme'; import { Text as TextComponent, Props as TextProps, } from '../text/text.component'; -import { TextStyleProps } from '@kitten/ui/common/props'; interface RadioProps { - style?: StyleProp; + textStyle?: StyleProp; text?: string; checked?: boolean; status?: string; @@ -61,9 +59,7 @@ export class Radio extends React.Component { }; private getComponentStyle = (style: StyleType): StyleType => { - - const derivedStyle: TextStyle = StyleSheet.flatten(this.props.style); - const { rest: derivedContainerStyle, ...derivedTextStyle } = allWithRest(derivedStyle, TextStyleProps); + const { style: containerStyle, textStyle } = this.props; const { textMarginHorizontal, @@ -84,7 +80,7 @@ export class Radio extends React.Component { return { container: { - ...derivedContainerStyle, + ...StyleSheet.flatten(containerStyle), ...styles.container, }, highlightContainer: styles.highlightContainer, @@ -99,7 +95,7 @@ export class Radio extends React.Component { fontWeight: textFontWeight, color: textColor, ...styles.text, - ...derivedTextStyle, + ...StyleSheet.flatten(textStyle), }, icon: { width: iconWidth, diff --git a/src/framework/ui/radio/radio.spec.tsx b/src/framework/ui/radio/radio.spec.tsx index a633b0438..8c38de3e9 100644 --- a/src/framework/ui/radio/radio.spec.tsx +++ b/src/framework/ui/radio/radio.spec.tsx @@ -113,6 +113,16 @@ describe('@radio: matches snapshot', () => { expect(inactiveOutput).toMatchSnapshot('checked'); }); + it('with text (styled)', () => { + const component: RenderAPI = renderComponent({ + text: 'Place your text', + textStyle: { fontSize: 22, lineHeight: 24 }, + }); + const { output } = shallow(component.getByType(RadioComponent)); + + expect(output).toMatchSnapshot(); + }); + }); describe('@radio: component checks', () => { diff --git a/src/framework/ui/radio/radio.spec.tsx.snap b/src/framework/ui/radio/radio.spec.tsx.snap index d3c9bd383..901651b2a 100644 --- a/src/framework/ui/radio/radio.spec.tsx.snap +++ b/src/framework/ui/radio/radio.spec.tsx.snap @@ -1383,3 +1383,195 @@ exports[`@radio: matches snapshot disabled 1`] = ` `; + +exports[`@radio: matches snapshot with text (styled) 1`] = ` + + + + + + + + + Place your text + + +`; diff --git a/src/framework/ui/tab/tab.component.tsx b/src/framework/ui/tab/tab.component.tsx index 05c938bd0..ca4f5aef6 100644 --- a/src/framework/ui/tab/tab.component.tsx +++ b/src/framework/ui/tab/tab.component.tsx @@ -8,7 +8,6 @@ import { TextStyle, } from 'react-native'; import { - allWithRest, styled, StyledComponentProps, StyleType, @@ -17,11 +16,10 @@ import { Text as TextComponent, Props as TextProps, } from '../text/text.component'; -import { TextStyleProps } from '../common/props'; interface TabProps { - style?: StyleProp; title?: string; + titleStyle?: StyleProp; icon?: (style: StyleType) => React.ReactElement; selected?: boolean; onSelect?: (selected: boolean) => void; @@ -47,8 +45,7 @@ export class Tab extends React.Component { }; private getComponentStyle = (source: StyleType): StyleType => { - const derivedStyle: TextStyle = StyleSheet.flatten(this.props.style); - const { rest: derivedContainerStyle, ...derivedTextStyle } = allWithRest(derivedStyle, TextStyleProps); + const { titleStyle } = this.props; const { textMarginVertical, @@ -66,7 +63,6 @@ export class Tab extends React.Component { return { container: { ...containerParameters, - ...derivedContainerStyle, ...styles.container, }, icon: { @@ -82,7 +78,7 @@ export class Tab extends React.Component { lineHeight: textLineHeight, fontWeight: textFontWeight, color: textColor, - ...derivedTextStyle, + ...StyleSheet.flatten(titleStyle), ...styles.title, }, }; diff --git a/src/framework/ui/tab/tab.spec.tsx b/src/framework/ui/tab/tab.spec.tsx index b39072628..bd9350bfc 100644 --- a/src/framework/ui/tab/tab.spec.tsx +++ b/src/framework/ui/tab/tab.spec.tsx @@ -91,6 +91,22 @@ describe('@tab: component checks', () => { expect(output).toMatchSnapshot(); }); + it('* title (styled)', () => { + const component: RenderAPI = render( + , + ); + + const { output } = shallow(component.getByType(TabComponent)); + + expect(output).toMatchSnapshot(); + }); + }); describe('@tab-bar: component checks', () => { diff --git a/src/framework/ui/tab/tab.spec.tsx.snap b/src/framework/ui/tab/tab.spec.tsx.snap index bd048ecd0..cfaa621df 100644 --- a/src/framework/ui/tab/tab.spec.tsx.snap +++ b/src/framework/ui/tab/tab.spec.tsx.snap @@ -265,6 +265,151 @@ exports[`@tab: component checks * icon 1`] = ` `; +exports[`@tab: component checks * title (styled) 1`] = ` + + + title + + +`; + exports[`@tab: component checks * title 1`] = ` ; interface TabBarProps { children: TabElement | TabElement[]; selectedIndex?: number; + indicatorStyle?: StyleProp; onSelect?: (index: number) => void; } @@ -51,6 +54,7 @@ export class TabBar extends React.Component { }; private getComponentStyle = (source: StyleType): StyleType => { + const { indicatorStyle } = this.props; const { indicatorHeight, indicatorBorderRadius, @@ -64,6 +68,7 @@ export class TabBar extends React.Component { height: indicatorHeight, borderRadius: indicatorBorderRadius, backgroundColor: indicatorBackgroundColor, + ...StyleSheet.flatten(indicatorStyle), }, }; }; diff --git a/src/framework/ui/tab/tabView.component.tsx b/src/framework/ui/tab/tabView.component.tsx index 853c429b2..8c15617ed 100644 --- a/src/framework/ui/tab/tabView.component.tsx +++ b/src/framework/ui/tab/tabView.component.tsx @@ -1,8 +1,9 @@ import React from 'react'; import { - Dimensions, + StyleProp, View, ViewProps, + ViewStyle, } from 'react-native'; import { styled } from '@kitten/theme'; import { @@ -33,6 +34,7 @@ interface TabViewProps { children: ChildElement | ChildElement[]; selectedIndex?: number; contentWidth?: number; + indicatorStyle?: StyleProp; shouldLoadComponent?: (index: number) => boolean; onOffsetChange?: (offset: number) => void; onSelect?: (index: number) => void; @@ -92,7 +94,13 @@ export class TabView extends React.Component { }; public render(): React.ReactElement { - const { selectedIndex, contentWidth, children, ...derivedProps } = this.props; + const { + selectedIndex, + contentWidth, + children, + indicatorStyle, + ...derivedProps + } = this.props; const { tabs, content } = this.renderComponentChildren(children); return ( @@ -100,6 +108,7 @@ export class TabView extends React.Component { {tabs} diff --git a/src/framework/ui/tooltip/tooltip.component.tsx b/src/framework/ui/tooltip/tooltip.component.tsx index bb9f4f122..846560af0 100644 --- a/src/framework/ui/tooltip/tooltip.component.tsx +++ b/src/framework/ui/tooltip/tooltip.component.tsx @@ -1,7 +1,9 @@ import React from 'react'; import { ImageProps, + StyleProp, StyleSheet, + TextStyle, View, ViewProps, } from 'react-native'; @@ -22,6 +24,7 @@ import { Omit } from '../common/type'; interface TooltipProps { text: string; + textStyle?: StyleProp; icon?: (style: StyleType) => React.ReactElement; children: React.ReactElement; } @@ -40,6 +43,7 @@ export class Tooltip extends React.Component { }; private getComponentStyle = (source: StyleType): StyleType => { + const { textStyle } = this.props; const { popoverPaddingHorizontal, popoverPaddingVertical, @@ -76,6 +80,7 @@ export class Tooltip extends React.Component { fontSize: textFontSize, lineHeight: textLineHeight, color: textColor, + ...StyleSheet.flatten(textStyle), ...styles.text, }, }; diff --git a/src/framework/ui/topNavigation/topNavigation.component.tsx b/src/framework/ui/topNavigation/topNavigation.component.tsx index 69874c24d..5b8d61a9f 100644 --- a/src/framework/ui/topNavigation/topNavigation.component.tsx +++ b/src/framework/ui/topNavigation/topNavigation.component.tsx @@ -5,6 +5,8 @@ import { ViewProps, Text, TextProps, + StyleProp, + TextStyle, } from 'react-native'; import { StyledComponentProps, @@ -20,7 +22,9 @@ type ActionElement = React.ReactElement; interface TopNavigationProps { title?: string; + titleStyle?: StyleProp; subtitle?: string; + subtitleStyle?: StyleProp; alignment?: string | TopNavigationAlignment; leftControl?: ActionElement; rightControls?: ActionElement[]; @@ -33,7 +37,13 @@ export class TopNavigation extends React.Component { static styledComponentName: string = 'TopNavigation'; private getComponentStyle = (style: StyleType): StyleType => { - const { alignment: alignmentValue, leftControl, rightControls } = this.props; + const { + alignment: alignmentValue, + leftControl, + rightControls, + titleStyle, + subtitleStyle, + } = this.props; const { titleTextAlign, @@ -73,6 +83,7 @@ export class TopNavigation extends React.Component { lineHeight: titleLineHeight, fontWeight: titleFontWeight, color: titleColor, + ...StyleSheet.flatten(titleStyle), ...styles.title, }, subtitle: { @@ -80,6 +91,8 @@ export class TopNavigation extends React.Component { fontSize: subtitleFontSize, color: subtitleColor, fontWeight: subtitleFontWeight, + lineHeight: subtitleLineHeight, + ...StyleSheet.flatten(subtitleStyle), ...styles.subtitle, }, action: { diff --git a/src/framework/ui/topNavigation/topNavigation.spec.tsx b/src/framework/ui/topNavigation/topNavigation.spec.tsx index 990110e70..2b566df23 100644 --- a/src/framework/ui/topNavigation/topNavigation.spec.tsx +++ b/src/framework/ui/topNavigation/topNavigation.spec.tsx @@ -91,6 +91,21 @@ describe('@top-navigation-bar/action', () => { expect(output).toMatchSnapshot(); }); + it('* texts (styled)', () => { + const component: RenderAPI = render( + , + ); + + const { output } = shallow(component.getByType(TopNavigationComponent)); + + expect(output).toMatchSnapshot(); + }); + it('* bar/alignment: center', () => { const component: RenderAPI = render( `; + +exports[`@top-navigation-bar/action * texts (styled) 1`] = ` + + + + + Test + + + Subtitle + + + + +`; diff --git a/src/playground/src/ui/screen/bottomNavigation.component.tsx b/src/playground/src/ui/screen/bottomNavigation.component.tsx index 99c94d620..c8bf964c8 100644 --- a/src/playground/src/ui/screen/bottomNavigation.component.tsx +++ b/src/playground/src/ui/screen/bottomNavigation.component.tsx @@ -69,15 +69,21 @@ function navigateToTab(routeName: string, navigate: (routeName: string) => void) function renderBottomNavigation(props: CommonNavigationProps): React.ReactElement { const routes: NavigationRoute[] = props.navigation.state.routes; const index: number = props.navigation.state.index; + const indicatorStyle: StyleType | null = index === 1 ? { backgroundColor: 'red' } : null; return ( navigateToTab(getRouteName(routes, selectedIndex), props.navigation.navigate)}> ( , }, { @@ -80,7 +81,7 @@ class OverflowMenuScreen extends React.Component { this.setState({ overflowMenu4Visible: !this.state.overflowMenu4Visible }); }; - private onSelectItem = (event: GestureResponderEvent, index: number): void => { + private onSelectItem = (index: number, event: GestureResponderEvent): void => { Alert.alert(`Selected item\'s index: ${index}`); }; diff --git a/src/playground/src/ui/screen/tooltip.component.tsx b/src/playground/src/ui/screen/tooltip.component.tsx index 756ce34fb..0d48bde58 100644 --- a/src/playground/src/ui/screen/tooltip.component.tsx +++ b/src/playground/src/ui/screen/tooltip.component.tsx @@ -75,7 +75,14 @@ class TooltipScreen extends React.Component { }; public render(): React.ReactNode { - const { container, componentContainer, component, tip, text } = this.props.themedStyle; + const { + container, + componentContainer, + component, + tip, + text, + bottomStartText, + } = this.props.themedStyle; return ( @@ -85,6 +92,7 @@ class TooltipScreen extends React.Component { placement={`${PLACEMENT} start`} visible={this.state.startVisible} text='Place your text here️' + textStyle={bottomStartText} onRequestClose={this.onStartPress}> ({ component: { // tooltip customization place }, + bottomStartText: { + fontSize: 16, + }, tip: { justifyContent: 'center', borderWidth: 4,