All files / UI_Component/common TTS.js

90% Statements 18/20
75% Branches 6/8
100% Functions 10/10
89.47% Lines 17/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90                                        45x 45x                   15x             44x 4x 4x                       5x 5x         5x 1x           46x   46x 46x 90x     46x               5x         5x        
/**
 * @author Haipeng Zhang(hp.zhang@samsung.com)
 * @fileoverview This module manages TTS item.
 * @date    2017/07/31 (last modified date)
 *
 * Copyright 2017 by Samsung Electronics, Inc.,
 *
 * This software is the confidential and proprietary information
 * of Samsung Electronics, Inc. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Samsung.
 */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { VOICE_GUIDE_DELAY } from './CommonDefine';
 
export default class TTS extends Component {
 
    constructor(props) {
        super(props);
        this.delayFocusTimer = null;
    }
 
    componentDidMount() {
    }
 
    componentWillReceiveProps(nextProps) {
    }
 
    shouldComponentUpdate(nextProps, nextState) {
        return (JSON.stringify(nextProps) !== JSON.stringify(this.props));
    }
 
    componentDidUpdate(prevProps, prevState) {
    }
 
    componentWillUnmount() {
        if (this.delayFocusTimer) {
            clearTimeout(this.delayFocusTimer);
            this.delayFocusTimer = null;
        }
    }
 
    /**
    * voice guide play
    * @name playTTS
    * @method
    * @param
    * @memberof
    */
    playTTS() {
        Eif (this.props.ttsEnable) {
            Iif (this.delayFocusTimer) {
                clearTimeout(this.delayFocusTimer);
                this.delayFocusTimer = null;
            }
 
            this.delayFocusTimer = setTimeout(() => {
                this.TTSnode.focus();
            }, VOICE_GUIDE_DELAY);
        }
    }
 
    render() {
        const { ttsEnable, ttsText } = this.props;
 
        let TTSComponent = null;
        if (ttsEnable) {
            TTSComponent = <div ref={(TTSnode) => { this.TTSnode = TTSnode; }} role='' style={{ opacity: 0 }}>{ttsText}</div>;
        }
 
        return (
          <div>
            {TTSComponent}
          </div>
        );
    }
}
 
TTS.defaultProps = {
    ttsEnable: PropTypes.bool,
    ttsText: '',
};
 
TTS.propTypes = {
    ttsEnable: PropTypes.bool,
    ttsText: PropTypes.string,
};