import * as React from 'react' import { View, StyleSheet } from 'react-native' import { AppHelper, TypeComponent } from '@ticmakers-react-native/core' import Button from '@ticmakers-react-native/button' import Dots from './../Dots/Dots' import DoneButton from './../Pagination/DoneButton' import { IPaginationProps, IPaginationState, TypePaginationPosition, IDotsProps } from './../../index' import styles from './styles' /** * Class to define the Pagination component used in Onboarding * @class Pagination * @extends {React.Component} */ export default class Pagination extends React.Component { /** * Method that renders the component * @returns {TypeComponent} */ public render(): TypeComponent { const { bottomBarHeight, containerStyle, style } = this._processProps() const _style = StyleSheet.flatten([{ height: bottomBarHeight, ...styles.container }, containerStyle, style]) return( { this.LeftContent() } { this.CenterContent() } { this.RightContent() } ) } /** * Method that renders the left container component * @returns {TypeComponent} */ public LeftContent(): TypeComponent { const { leftContainerStyle } = this._processProps() const _style = StyleSheet.flatten([styles.leftContainer, leftContainerStyle]) return { this._getContent('left') } } /** * Method that renders the center container component * @returns {TypeComponent} */ public CenterContent(): TypeComponent { const { centerContainerStyle } = this._processProps() const _style = StyleSheet.flatten([styles.centerContainer, centerContainerStyle]) return { this._getContent('center') } } /** * Method that renders the right container component * @returns {TypeComponent} */ public RightContent(): TypeComponent { const { rightContainerStyle } = this._processProps() const _style = StyleSheet.flatten([styles.rightContainer, rightContainerStyle]) return { this._getContent('right') } } /** * Method that renders the Done button * @returns {TypeComponent} */ public Done(): TypeComponent { const { DoneComponent, allowFontScaling, doneLabel, doneStyle, hideDone, isLight, onDone } = this._processProps() const props = { allowFontScaling, key: 'done', onPress: () => onDone && onDone(), style: StyleSheet.flatten([!isLight && styles.colorLight, { alignSelf: 'center' }, doneStyle]), title: doneLabel, } if (!hideDone && this.isLastPage()) { if (AppHelper.isComponent(DoneComponent) || AppHelper.isElement(DoneComponent)) { const _s = StyleSheet.flatten([props.style, (DoneComponent as any).props.style]) const _p = { ...props, ...(DoneComponent as any).props, style: _s } return React.cloneElement(DoneComponent as any, _p) // tslint:disable-next-line: no-else-after-return } else if (props.title) { return React.cloneElement(DoneButton as any, props) } return } } /** * Method that renders the pagination Dots * @returns {TypeComponent} */ public Dots(): TypeComponent { const { DotComponent, currentPage, dotColorSelected, dotSelectedStyle, dotsColor, dotsSize, dotsStyle, hideDots, isLight, numPages } = this._processProps() const props: IDotsProps = { DotComponent, currentPage, isLight, numPages, // tslint:disable-next-line: object-literal-sort-keys colorSelected: dotColorSelected, color: dotsColor, key: 'dots', selectedStyle: dotSelectedStyle, size: dotsSize, style: StyleSheet.flatten([styles.dots, dotsStyle]), } if (!hideDots) { return } } /** * Method that renders the Next button * @returns {TypeComponent} */ public Next(): TypeComponent { const { NextComponent, allowFontScaling, hideNext, isLight, nextLabel, nextStyle, onNext } = this._processProps() const props = { allowFontScaling, key: 'next', onPress: () => onNext && onNext(), style: StyleSheet.flatten([!isLight && styles.colorLight, { alignSelf: 'center' }, nextStyle]), title: nextLabel, } if (!hideNext && !this.isLastPage()) { if (AppHelper.isComponent(NextComponent) || AppHelper.isElement(NextComponent)) { return React.cloneElement(NextComponent as any, props) } return