import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, DeviceEventEmitter } from 'react-native'; import FastImage from 'react-native-fast-image'; import { colors, px2dp } from '../../utils'; interface Props { type?: 'single' | 'mutiple' onPressLeft?: Function onPressRight?: Function onPressBtn?: Function title?: string leftTitle?: string rightTitle?: string leftMarkerNumber?: number rightMarkerNumber?: number backgroundColor?: string btnTextColor?: string } interface State { } export default class KitFloatBottomBtn extends React.Component { constructor(props: Props) { super(props); }; public delayTimer = null; public btnContainerRef = null; public keyboardShowListener = null; public keyboardHideListner = null; public readonly state: Readonly = { }; componentDidMount(): void { this.keyboardShowListener = DeviceEventEmitter.addListener("app_keyboard_did_show", (a) => { requestAnimationFrame(() => { this.btnContainerRef.setNativeProps({ style: { height: px2dp(0), marginVertical: px2dp(0) } }) }) }) this.keyboardHideListner = DeviceEventEmitter.addListener("app_keyboard_did_hide", (a) => { const { type = 'single' } = this.props; this.delayTimer = setTimeout(() => { requestAnimationFrame(() => { this.btnContainerRef.setNativeProps({ style: { height: type == 'single' ? px2dp(36) : px2dp(54), } }) }) }, 100); }) } componentWillUnmount() { this.delayTimer && clearTimeout(this.delayTimer); this.keyboardHideListner && this.keyboardHideListner.remove(); this.keyboardShowListener && this.keyboardShowListener.remove(); this.setState = (state, callback) => { return; } } render() { const { type = 'single', onPressLeft, onPressRight, leftTitle, rightTitle, title, onPressBtn, leftMarkerNumber = 0, rightMarkerNumber = 0, backgroundColor = colors.themeColor, btnTextColor = '#fff' } = this.props; return ( <> { type == 'mutiple' ? this.btnContainerRef = c} style={styles.twoBtnContainer} > onPressLeft()} > {leftMarkerNumber} {leftTitle} 1 onPressRight()} > 1 {rightTitle} 1 : this.btnContainerRef = c} style={[styles.btnContainer, { backgroundColor: backgroundColor }]} > onPressBtn()} style={styles.btnContent} > {title} } ) } } const styles = StyleSheet.create({ twoBtnContainer: { position: 'absolute', bottom: px2dp(0), left: px2dp(0), width: px2dp(375), height: px2dp(54), flexDirection: 'row', zIndex: 999, justifyContent: 'space-between', alignItems: 'center', overflow: 'hidden', paddingBottom: px2dp(18), paddingHorizontal: px2dp(13) }, btnContainer: { position: 'absolute', bottom: px2dp(18), left: px2dp(13), width: px2dp(350), height: px2dp(36), borderRadius: px2dp(18), backgroundColor: colors.themeColor, overflow: 'hidden', zIndex: 999, elevation: 6 }, btnContent: { width: '100%', height: '100%', justifyContent: 'center', alignItems: 'center' }, halfBtnLeft: { width: px2dp(172), height: '100%', backgroundColor: colors.blueColor, justifyContent: 'center', alignItems: 'center', borderTopLeftRadius: px2dp(18), borderBottomLeftRadius: px2dp(18), borderTopRightRadius: px2dp(3), borderBottomRightRadius: px2dp(3), elevation: 6, flexDirection: 'row', overflow: 'hidden', }, halfBtnRight: { width: px2dp(172), height: '100%', backgroundColor: colors.themeColor, justifyContent: 'center', alignItems: 'center', borderTopRightRadius: px2dp(18), borderBottomRightRadius: px2dp(18), borderTopLeftRadius: px2dp(3), borderBottomLeftRadius: px2dp(3), elevation: 6 }, marker: { width: px2dp(20), height: px2dp(20), backgroundColor: colors.redColor, elevation: 2, borderWidth: 1, borderColor: '#fff', borderRadius: px2dp(10), justifyContent: 'center', alignItems: 'center', marginHorizontal: px2dp(3), }, btnText: { fontSize: 15, color: '#fff' }, markerText: { fontSize: 13, color: '#fff' } })