Skip to content

Commit b115755

Browse files
handling back button on lecture - changed close course action slightly
1 parent 4012611 commit b115755

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

mobileClient/components/Course.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Course extends React.Component {
3838
backgroundColor: this.props.backgroundColor,
3939
alignItems: 'center'
4040
}}>
41-
<Lecture />
41+
<Lecture closeCourse={this.props.closeCourse}/>
4242
<View style={{position: 'absolute', bottom: 25, alignSelf: 'center'}}>
4343
<CircleButton radius={45} withStaticCircles>
4444
<Image

mobileClient/components/Home.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ class Home extends React.Component {
232232

233233
closeCourse = async () => {
234234
await mutationConnectionHandler(this.props.history, async () => {
235+
await this.props.closeCourse()
235236
this.props.dispatch(courseActions.close())
236237
this.setState({ isExitAnimationFinished: false })
237238
this.closeMenu()
238-
await this.props.closeCourse()
239239
this.enableCourseSelector()
240240
})
241241
}
@@ -326,7 +326,7 @@ class Home extends React.Component {
326326

327327
</View>}
328328

329-
{isExitAnimationFinished && <Course />}
329+
{isExitAnimationFinished && <Course closeCourse={this.closeCourse}/>}
330330

331331
{this.props.mainMenu.visible && <MainMenu closeCourse={this.closeCourse} logoutAction={this.logoutAction}/>}
332332
</View>

mobileClient/components/Lecture.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

33
import React from 'react'
4-
import { Animated, Easing, Text, View } from 'react-native'
4+
import { Animated, Easing, Text, View, BackHandler} from 'react-native'
55
import { compose, graphql } from 'react-apollo'
66
import { connect } from 'react-redux'
77
import { withRouter } from 'react-router-native'
@@ -19,6 +19,7 @@ import currentLessonQuery from '../shared/graphql/queries/currentLesson'
1919
import WithData from './WithData'
2020
import { mutationConnectionHandler } from './NoInternet'
2121
import Loading from './Loading'
22+
import * as mainMenuActions from '../actions/MainMenuActions'
2223

2324
class 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

104121
export default compose(
105122
connect(mapStateToProps),
123+
connect(state => state),
106124
withRouter,
107125
graphql(clearNotCasualItems, {
108126
props: ({ ownProps, mutate }) => ({

0 commit comments

Comments
 (0)