11// @flow
22
33import React from 'react'
4- import { Animated , Easing , Text , View } from 'react-native'
4+ import { Animated , Easing , Text , View , BackHandler } from 'react-native'
55import { compose , graphql } from 'react-apollo'
66import { connect } from 'react-redux'
77import { withRouter } from 'react-router-native'
@@ -19,6 +19,7 @@ import currentLessonQuery from '../shared/graphql/queries/currentLesson'
1919import WithData from './WithData'
2020import { mutationConnectionHandler } from './NoInternet'
2121import Loading from './Loading'
22+ import * as mainMenuActions from '../actions/MainMenuActions'
2223
2324class Lecture extends React . Component {
2425 state = {
@@ -31,13 +32,29 @@ class Lecture extends React.Component {
3132 }
3233
3334 componentDidMount ( ) {
35+ BackHandler . addEventListener ( 'hardwareBackPress' , this . handleBack )
3436 Animated . timing ( this . infoScale , {
3537 toValue : 1 ,
3638 duration : 500 ,
3739 easing : Easing . elastic ( 1 )
3840 } ) . start ( ( ) => this . setState ( { showLecture : true } ) )
3941 }
4042
43+ componentWillUnmount = ( ) => {
44+ BackHandler . removeEventListener ( 'hardwareBackPress' , this . handleBack )
45+ }
46+
47+ handleBack = ( ) => {
48+ if ( this . props . mainMenu . visible ) {
49+ this . props . dispatch ( mainMenuActions . updateMainMenuVisibility ( {
50+ visible : false
51+ } ) )
52+ return true
53+ }
54+ this . props . closeCourse ( )
55+ return true
56+ }
57+
4158 onChangeState = async ( event ) => {
4259 // console.log('Gozdecki: event in lecture', event)
4360 if ( event . state === 'ended' ) {
@@ -103,6 +120,7 @@ const mapStateToProps = (state) => {
103120
104121export default compose (
105122 connect ( mapStateToProps ) ,
123+ connect ( state => state ) ,
106124 withRouter ,
107125 graphql ( clearNotCasualItems , {
108126 props : ( { ownProps, mutate } ) => ( {
0 commit comments