import * as React from 'react' import {Component} from 'react'; import {View, Animated, ScrollView, Text, TouchableWithoutFeedback, Platform, Dimensions, ViewStyle} from 'react-native' import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons' import Ripple from 'react-native-material-ripple'; const navBarHeight = (Platform.OS === "ios") ? 64 : 54; const {width, height} = Dimensions.get("window"); const screenHeight = width < height ? height : width; export interface MaterialBackdropProps { revealComponent?(): React.ReactNode, backdropBackgroundColor?: string, leftButtonIcon?: string, expandedTitle?: string, collapsedTitle?: string, content?(): React.ReactNode, textColor?: string, subHeaderText?: string, horizontalContent?: boolean, onSubheaderClick?(): void, onLeftButtonClick?(): void, onRightButtonClick?(): void, contentBackgroundColor?: string, subheaderTextColor?: string, onExpand?(): void, onCollapse?(): void, rightButtonIcon?: string, style?: ViewStyle } export interface MaterialBackdropState { isExpanded: boolean, height: number } export default class MaterialBackdrop extends Component { ViewScale = new Animated.Value(0); static defaultProps = { revealComponent:() => null, content: () => null, onSubheaderClick: () => {}, onLeftButtonClick: () => {}, onRightButtonClick: () => {}, onExpand: () => {}, onCollapse: () => {} }; constructor(props) { super(props); this.state = {isExpanded: false, height: 0} } render() { return ( {this.props.leftButtonIcon && { if (this.props.onLeftButtonClick) { this.props.onLeftButtonClick(); } this.state.isExpanded ? this.collapse() : this.expand() }}> } {this.props.rightButtonIcon && { if (this.props.onRightButtonClick) { this.props.onRightButtonClick(); } this.state.isExpanded ? this.collapse() : this.expand() }}> } {this.state.isExpanded ? this.props.expandedTitle : this.props.collapsedTitle} { const {height} = event.nativeEvent.layout; this.setState({height: height > screenHeight - navBarHeight - 1 ? screenHeight - 2 * navBarHeight - 16 : height}) }}> {this.props.revealComponent()} {this.props.subHeaderText && { this.collapse(); if (this.props.onSubheaderClick) { this.props.onSubheaderClick(); } }} style={{height: 40, paddingBottom: 8, width: '100%'}}> {this.props.subHeaderText} } {this.props.content()} ) } collapse = () => { this.setState({isExpanded: false}, () => { if (this.props.onCollapse) { this.props.onCollapse(); } }); Animated.timing( this.ViewScale, { useNativeDriver: true, toValue: 0, duration: 200, } ).start(); }; expand = () => { this.setState({isExpanded: true}, () => { if (this.props.onExpand) { this.props.onExpand(); } }); Animated.timing( this.ViewScale, { useNativeDriver: true, toValue: this.state.height, duration: 200, } ).start(); } }