diff --git a/src/commons/asBaseComponent.tsx b/src/commons/asBaseComponent.tsx index 3a476b018f..1292840701 100644 --- a/src/commons/asBaseComponent.tsx +++ b/src/commons/asBaseComponent.tsx @@ -18,11 +18,6 @@ export interface AsBaseComponentOptions { modifiersOptions?: Modifiers.ModifiersOptions; } -// TODO: find a proper way to inject this type in the private repo -type ThemeComponent = { - useCustomTheme?: boolean; -}; - const EMPTY_MODIFIERS = {}; function asBaseComponent(WrappedComponent: React.ComponentType, diff --git a/src/components/chipsInput/index.tsx b/src/components/chipsInput/index.tsx index ffaa60b302..8879039ce8 100644 --- a/src/components/chipsInput/index.tsx +++ b/src/components/chipsInput/index.tsx @@ -484,6 +484,7 @@ class ChipsInput extends Component { const Container = maxHeight ? ScrollView : View; return ( {!isTop && !!toastHeight && this.renderAttachmentContent()} - {this.renderContent()} - + {isTop && !!toastHeight && this.renderAttachmentContent()} - + ); } } diff --git a/src/components/view/index.tsx b/src/components/view/index.tsx index bf5ab39eb6..ab249dfb1d 100644 --- a/src/components/view/index.tsx +++ b/src/components/view/index.tsx @@ -1,16 +1,10 @@ -import React, {PureComponent} from 'react'; +import {useModifiers, useThemeProps} from 'hooks'; +import React, {useEffect, useMemo, useState} from 'react'; import {View as RNView, SafeAreaView, Animated, ViewProps as RNViewProps, StyleProp, ViewStyle} from 'react-native'; import Reanimated from 'react-native-reanimated'; -import { - Constants, - asBaseComponent, - forwardRef, - BaseComponentInjectedProps, - ForwardRefInjectedProps, - ContainerModifiers -} from '../../commons/new'; +import {Constants, ContainerModifiers} from '../../commons/new'; -export interface ViewProps extends Omit, ContainerModifiers { +export interface ViewProps extends Omit, ThemeComponent, ContainerModifiers { /** * If true, will render as SafeAreaView */ @@ -46,11 +40,15 @@ export interface ViewProps extends Omit, ContainerModifier style?: StyleProp>; } -type PropsTypes = BaseComponentInjectedProps & ForwardRefInjectedProps & ViewProps; - -interface ViewState { - ready: boolean; -} +const modifiersOptions = { + backgroundColor: true, + borderRadius: true, + paddings: true, + margins: true, + alignments: true, + flex: true, + position: true +}; /** * @description: An enhanced View component @@ -58,94 +56,82 @@ interface ViewState { * @extendsLink: https://reactnative.dev/docs/view * @modifiers: margins, paddings, alignments, background, borderRadius */ -class View extends PureComponent { - static displayName = 'View'; - private Container: React.ClassType; - - constructor(props: PropsTypes) { - super(props); - - this.Container = props.useSafeArea && Constants.isIOS ? SafeAreaView : RNView; - if (props.reanimated) { - this.Container = Reanimated.createAnimatedComponent(this.Container); - } else if (props.animated) { - this.Container = Animated.createAnimatedComponent(this.Container); - } - - this.state = { - ready: !props.renderDelay - }; - } +function View(props: ViewProps, ref: any) { + const themeProps = useThemeProps(props, 'View'); + const { + renderDelay, + style, + // (!) extract left, top, bottom... props to avoid passing them on Android + /* eslint-disable */ + left, + top, + right, + bottom, + flex: propsFlex, + /* eslint-enable */ + inaccessible, + useSafeArea, + animated, + reanimated, + children, + ...others + } = themeProps; + const {backgroundColor, borderRadius, paddings, margins, alignments, flexStyle, positionStyle} = useModifiers(themeProps, + modifiersOptions); + const [ready, setReady] = useState(!renderDelay); - componentDidMount() { - const {renderDelay} = this.props; + useEffect(() => { if (renderDelay) { setTimeout(() => { - this.setState({ready: true}); + setReady(true); }, renderDelay); } - } + }, []); - // TODO: do we need this? - setNativeProps(nativeProps: any) { - //@ts-ignore - this._root.setNativeProps(nativeProps); // eslint-disable-line - } + const ViewContainer = useMemo(() => { + const container = useSafeArea && Constants.isIOS ? SafeAreaView : RNView; - render() { - if (!this.state.ready) { - return null; + if (reanimated) { + return Reanimated.createAnimatedComponent(container); + } else if (animated) { + return Animated.createAnimatedComponent(container); } - // (!) extract left, top, bottom... props to avoid passing them on Android - // eslint-disable-next-line - const { - modifiers, - style, - /* eslint-disable */ - left, - top, - right, - bottom, - flex: propsFlex, - /* eslint-enable */ - forwardedRef, - inaccessible, - ...others - } = this.props; - const {backgroundColor, borderRadius, paddings, margins, alignments, flexStyle, positionStyle} = modifiers; - const Element = this.Container; - return ( - - {this.props.children} - - ); + return container; + }, [useSafeArea, animated, reanimated]); + + const _style = useMemo(() => { + return [ + backgroundColor && { + backgroundColor + }, + borderRadius && { + borderRadius + }, + flexStyle, + positionStyle, + paddings, + margins, + alignments, + style + ]; + }, [backgroundColor, borderRadius, flexStyle, positionStyle, paddings, margins, alignments, style]); + + if (!ready) { + return null; } -} -const modifiersOptions = { - backgroundColor: true, - borderRadius: true, - paddings: true, - margins: true, - alignments: true, - flex: true, - position: true -}; + return ( + + {children} + + ); +} -export default asBaseComponent(forwardRef(View), {modifiersOptions}); +export default React.forwardRef(View); diff --git a/typings/globalTypes.d.ts b/typings/globalTypes.d.ts index 995873f030..e02375ce40 100644 --- a/typings/globalTypes.d.ts +++ b/typings/globalTypes.d.ts @@ -14,3 +14,7 @@ declare module 'react-native-measureme'; interface Extendable { [key: string]: any; } + +interface ThemeComponent { + useCustomTheme?: boolean; +}