import React, { FunctionComponent} from 'react' import { View, Text, TouchableOpacity } from 'react-native'; import Icon from '../icon/index' import { IComponent, ComponentDefaults } from '../utils/typings' import pt from '../utils/pt' import { useConfig } from '../configprovider'; import backTopStyles from './styles'; export interface BackTopProps extends IComponent { className?: string bottom: number right: number elId: string distance: number zIndex: number isAnimation: boolean duration: number children?: HTMLElement | any style?: React.CSSProperties isShow: boolean onPress?: (event: MouseEvent) => void } const defaultProps = { ...ComponentDefaults, bottom: 20, right: 10, elId: 'body', distance: 200, zIndex: 10, isAnimation: true, duration: 1000, isShow:false } as BackTopProps export const BackTop: FunctionComponent< Partial & Omit, 'onPress'> > = (props) => { const { children, bottom, right, elId, distance, zIndex, isAnimation, className, duration, style, onPress, iconClassPrefix, iconFontClassName, isShow } = { ...defaultProps, ...props, } const { theme } = useConfig(); const mStyles = backTopStyles(theme); // 返回顶部点击事件 const goTop = (e: any) => { onPress && onPress(e) } const backTopClass = { position:'absolute', right: pt(Number(right)), bottom: pt(Number(bottom)), zIndex, } if(isShow){ return ( { goTop(e) }} > {children || ( 顶部 )} ) }else{ return null; } } BackTop.defaultProps = defaultProps BackTop.displayName = 'NutBackTop'