Skip to content

Commit 54f13dc

Browse files
authored
NumberInput - support theme and generify useThemeProps (#2370)
1 parent 494d9a2 commit 54f13dc

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

src/commons/asBaseComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function asBaseComponent<PROPS, STATICS = {}>(WrappedComponent: React.ComponentT
6262
: Modifiers.generateModifiersStyle(options.modifiersOptions, themeProps);
6363
// TODO: omit original modifiers props (left, right, flex, etc..)
6464
// Because they throws an error when being passed to RNView on Android
65+
// @ts-expect-error
6566
const {forwardedRef, ...others} = themeProps;
6667
return (
6768
(this.state.error && UIComponent.defaultProps?.renderError) || (

src/commons/modifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export function extractComponentProps(component: any, props: Dictionary<any>, ig
333333
}
334334

335335
//@ts-ignore
336-
export function getThemeProps(props = this.props, context = this.context, componentDisplayName = '') {
336+
export function getThemeProps<T extends object>(props: T = this.props, context = this.context, componentDisplayName = ''):T {
337337
const componentName =
338338
//@ts-ignore
339339
componentDisplayName || this.displayName || this.constructor.displayName || this.constructor.name;

src/components/avatar/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@ const Avatar = forwardRef<any, AvatarProps>((props: AvatarProps, ref: React.Forw
301301
}, [_baseContainerStyle, imageStyle]);
302302

303303
const renderImage = () => {
304-
const hasImage = !_.isUndefined(_source);
305-
306-
if (hasImage) {
304+
if (_source !== undefined) {
307305
// Looks like reanimated does not support SVG
308306
const ImageContainer = animate && !isSvg(_source) ? AnimatedImage : Image;
309307
return (

src/components/numberInput/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {isEmpty} from 'lodash';
22
import React, {useMemo, useCallback, useState, useEffect} from 'react';
33
import {StyleSheet, StyleProp, ViewStyle} from 'react-native';
4-
import {useDidUpdate} from 'hooks';
4+
import {useDidUpdate, useThemeProps} from 'hooks';
55
import TextField, {TextFieldProps} from '../../incubator/TextField';
66
import Text from '../text';
77
import {getInitialData, parseInput, generateOptions, Options, NumberInputData} from './Presenter';
@@ -47,6 +47,7 @@ export type NumberInputProps = React.PropsWithRef<
4747
};
4848

4949
function NumberInput(props: NumberInputProps, ref: any) {
50+
const themeProps = useThemeProps(props, 'NumberInput');
5051
const {
5152
onChangeNumber,
5253
initialNumber,
@@ -60,7 +61,7 @@ function NumberInput(props: NumberInputProps, ref: any) {
6061
trailingTextStyle,
6162
placeholder,
6263
...others
63-
} = props;
64+
} = themeProps;
6465
const [options, setOptions] = useState<Options>(generateOptions(locale, fractionDigits));
6566
const [data, setData] = useState<NumberInputData>();
6667

src/components/picker/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
279279
disabled={themeProps.editable === false}
280280
>
281281
{renderPicker ? (
282+
// @ts-expect-error - hopefully will be solved after the picker migration ends
282283
renderPicker(value, label)
283284
) : (
284285
<TextFieldMigrator

src/hooks/useThemeProps/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ThemeManager} from 'style';
55

66
const EmptyContext = createContext({});
77

8-
const useThemeProps = (props: any, componentName: string) => {
8+
const useThemeProps = <T extends object>(props: T, componentName: string) => {
99
// Note: This adds a dependency on current color scheme and update theme props accordingly
1010
useColorScheme();
1111
const themeContext = ThemeManager.getThemeContext();

0 commit comments

Comments
 (0)