From e633dcda670b0070f04702fff07b815ccb4d9c52 Mon Sep 17 00:00:00 2001 From: Miki Leib <38354019+M-i-k-e-l@users.noreply.github.com> Date: Sun, 11 Aug 2024 11:28:23 +0300 Subject: [PATCH 01/11] TextField - only use leadingAccessoryRef when needed (i.e. floatingPlaceholder={true}) (#3197) --- src/components/textField/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/textField/index.tsx b/src/components/textField/index.tsx index e2e1ac8a53..a9d10b521f 100644 --- a/src/components/textField/index.tsx +++ b/src/components/textField/index.tsx @@ -70,7 +70,7 @@ const TextField = (props: InternalTextFieldProps) => { labelStyle, labelProps, // Accessory Buttons - leadingAccessory, + leadingAccessory: propsLeadingAccessory, trailingAccessory, topTrailingAccessory, bottomAccessory, @@ -107,12 +107,16 @@ const TextField = (props: InternalTextFieldProps) => { }, [fieldState, others.editable, readonly, validateField, checkValidity]); const leadingAccessoryClone = useMemo(() => { - if (leadingAccessory) { - return React.cloneElement(leadingAccessory, { + if (propsLeadingAccessory) { + return React.cloneElement(propsLeadingAccessory, { ref: leadingAccessoryRef }); } - }, [leadingAccessory]); + }, [propsLeadingAccessory]); + + const leadingAccessory = useMemo(() => { + return floatingPlaceholder ? leadingAccessoryClone : propsLeadingAccessory; + }, [floatingPlaceholder, leadingAccessoryClone, propsLeadingAccessory]); const {margins, paddings, typography, positionStyle, color} = modifiers; const typographyStyle = useMemo(() => omit(typography, 'lineHeight'), [typography]); @@ -161,7 +165,7 @@ const TextField = (props: InternalTextFieldProps) => { {/* */} - {leadingAccessoryClone} + {leadingAccessory} {/* Note: We're passing flexG to the View to support properly inline behavior - so the input will be rendered correctly in a row container. Known Issue: This slightly push the trailing accessory and clear button when entering a long text From 3437aca027da12f13c28c9be4462cddc3a1b37af Mon Sep 17 00:00:00 2001 From: Miki Leib <38354019+M-i-k-e-l@users.noreply.github.com> Date: Tue, 13 Aug 2024 09:59:30 +0300 Subject: [PATCH 02/11] Badge - fix labelStyle's type (#3207) --- src/components/badge/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/badge/index.tsx b/src/components/badge/index.tsx index fd4158876b..19e693e394 100644 --- a/src/components/badge/index.tsx +++ b/src/components/badge/index.tsx @@ -65,7 +65,7 @@ export type BadgeProps = ViewProps & /** * Additional styles for the badge label */ - labelStyle?: TextStyle; + labelStyle?: StyleProp; /** * Receives a number from 1 to 4, representing the label's max digit length. * Beyond the max number for that digit length, a "+" will show at the end. From bfea0342b0fbf55ec26c8a4c847e46a055e77dc1 Mon Sep 17 00:00:00 2001 From: Miki Leib <38354019+M-i-k-e-l@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:03:10 +0300 Subject: [PATCH 03/11] ColorSwatch - support theme and color modifiers (#3209) --- src/components/colorSwatch/index.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/colorSwatch/index.tsx b/src/components/colorSwatch/index.tsx index f71a479797..b3a697dbf9 100644 --- a/src/components/colorSwatch/index.tsx +++ b/src/components/colorSwatch/index.tsx @@ -2,7 +2,7 @@ import React, {PureComponent} from 'react'; import {StyleSheet, Animated, Easing, LayoutChangeEvent, StyleProp, ViewStyle} from 'react-native'; import Assets from '../../assets'; import {BorderRadiuses, Colors} from '../../style'; -import {Constants} from '../../commons/new'; +import {asBaseComponent, BaseComponentInjectedProps, Constants, ColorsModifiers} from '../../commons/new'; import View from '../view'; import TouchableOpacity from '../touchableOpacity'; import Image from '../image'; @@ -50,7 +50,7 @@ interface Props { */ size?: number; } -export type ColorSwatchProps = Props; +export type ColorSwatchProps = Props & ColorsModifiers; const transparentImage = require('./assets/transparentSwatch/TransparentSwatch.png'); const DEFAULT_SIZE = Constants.isTablet ? 44 : 36; @@ -62,7 +62,7 @@ export const SWATCH_SIZE = DEFAULT_SIZE; * @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/ColorPickerScreen.tsx * @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/ColorPalette/ColorPalette.gif?raw=true */ -class ColorSwatch extends PureComponent { +class ColorSwatch extends PureComponent { static displayName = 'ColorSwatch'; state = { @@ -71,7 +71,7 @@ class ColorSwatch extends PureComponent { animatedScale: new Animated.Value(0.5) }; - styles = createStyles(this.props); + styles = createStyles({...this.props, color: this.color}); layout = {x: 0, y: 0}; componentDidMount() { @@ -85,6 +85,11 @@ class ColorSwatch extends PureComponent { } } + get color() { + const {color, modifiers} = this.props; + return color || modifiers?.color; + } + animateSwatch(newValue: number) { const {animatedOpacity, animatedScale} = this.state; @@ -118,7 +123,8 @@ class ColorSwatch extends PureComponent { } onPress = () => { - const {color = '', value, index} = this.props; + const {value, index} = this.props; + const color = this.color ?? ''; const tintColor = this.getTintColor(value); const result = value || color; const hexString = Colors.getHexString(result); @@ -135,7 +141,7 @@ class ColorSwatch extends PureComponent { } getAccessibilityInfo() { - const {color} = this.props; + const color = this.color; return { accessibilityLabel: color && Colors.getColorName(color), @@ -152,7 +158,8 @@ class ColorSwatch extends PureComponent { }; renderContent() { - const {style, color, onPress, unavailable, size = DEFAULT_SIZE, ...others} = this.props; + const {style, onPress, unavailable, size = DEFAULT_SIZE, ...others} = this.props; + const color = this.color; const {isSelected} = this.state; const Container = onPress ? TouchableOpacity : View; const tintColor = this.getTintColor(color); @@ -213,7 +220,7 @@ class ColorSwatch extends PureComponent { } } -export default ColorSwatch; +export default asBaseComponent(ColorSwatch); function createStyles({color = Colors.grey30}) { return StyleSheet.create({ From 0144852034f1f614d4ca701b289bdd6c96780253 Mon Sep 17 00:00:00 2001 From: M-i-k-e-l Date: Wed, 14 Aug 2024 11:21:38 +0300 Subject: [PATCH 04/11] StackAggregator - prettify --- .../StackAggregatorScreen.tsx | 27 +++-- src/components/stackAggregator/index.tsx | 104 ++++++++---------- 2 files changed, 60 insertions(+), 71 deletions(-) diff --git a/demo/src/screens/componentScreens/StackAggregatorScreen.tsx b/demo/src/screens/componentScreens/StackAggregatorScreen.tsx index b4e7bfd1d7..e122872aff 100644 --- a/demo/src/screens/componentScreens/StackAggregatorScreen.tsx +++ b/demo/src/screens/componentScreens/StackAggregatorScreen.tsx @@ -3,7 +3,6 @@ import React, {Component} from 'react'; import {ScrollView} from 'react-native'; import {Colors, View, Text, Button, StackAggregator} from 'react-native-ui-lib'; - const TEXTS = [ 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', @@ -12,28 +11,28 @@ const TEXTS = [ ]; export default class StackAggregatorScreen extends Component { - state = { + state = { contents: TEXTS, collapsed: true }; onItemPress = (index: number) => { console.warn('item pressed: ', index); - } + }; onPress = (index: number) => { console.warn('item\'s button pressed: ', index); - } + }; refreshItems = () => { const newItems = _.clone(this.state.contents); newItems.push('New Item'); this.setState({contents: newItems}); - } + }; toggleCollapsed = () => { this.setState({collapsed: !this.state.collapsed}); - } + }; renderItem = (_: string, index: number) => { return ( @@ -42,7 +41,7 @@ export default class StackAggregatorScreen extends Component { {this.state.contents[index]} ); - } + }; render() { const {collapsed} = this.state; @@ -53,18 +52,18 @@ export default class StackAggregatorScreen extends Component {