import PropTypes from 'prop-types' import React from 'react' import { ActivityIndicator, Platform, StyleSheet, Text, TouchableOpacity, View, ViewPropTypes, ViewStyle, TextStyle, } from 'react-native' import Color from './Color' const styles = StyleSheet.create({ container: { alignItems: 'center', marginTop: 5, marginBottom: 10, }, wrapper: { alignItems: 'center', justifyContent: 'center', backgroundColor: Color.defaultColor, borderRadius: 15, height: 30, paddingLeft: 10, paddingRight: 10, }, text: { backgroundColor: Color.backgroundTransparent, color: Color.white, fontSize: 12, }, activityIndicator: { marginTop: Platform.select({ ios: -14, android: -16, }), }, }) interface LoadEarlierProps { isLoadingEarlier?: boolean label?: string containerStyle?: ViewStyle wrapperStyle?: ViewStyle textStyle?: TextStyle activityIndicatorStyle?: ViewStyle activityIndicatorColor?: string activityIndicatorSize?: number | 'small' | 'large' onLoadEarlier?(): void } export default class LoadEarlier extends React.Component { static defaultProps = { onLoadEarlier: () => {}, isLoadingEarlier: false, label: 'Load earlier messages', containerStyle: {}, wrapperStyle: {}, textStyle: {}, activityIndicatorStyle: {}, activityIndicatorColor: 'white', activityIndicatorSize: 'small', } static propTypes = { onLoadEarlier: PropTypes.func, isLoadingEarlier: PropTypes.bool, label: PropTypes.string, containerStyle: ViewPropTypes.style, wrapperStyle: ViewPropTypes.style, textStyle: PropTypes.any, activityIndicatorStyle: ViewPropTypes.style, activityIndicatorColor: PropTypes.string, activityIndicatorSize: PropTypes.string, } renderLoading() { if (this.props.isLoadingEarlier === false) { return ( {this.props.label} ) } return ( {this.props.label} ) } render() { return ( { if (this.props.onLoadEarlier) { this.props.onLoadEarlier() } }} disabled={this.props.isLoadingEarlier === true} accessibilityTraits='button' > {this.renderLoading()} ) } }