Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
86a2c008
Commit
86a2c008
authored
Jun 07, 2017
by
AuckeBos
Committed by
Gijs Hendriksen
Jun 14, 2017
Browse files
Hardware back button handling for android added
parent
1587949f
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/components/navigator.js
View file @
86a2c008
import
React
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
Text
,
View
,
StatusBar
,
TouchableOpacity
}
from
'
react-native
'
;
import
{
Text
,
View
,
StatusBar
,
TouchableOpacity
,
BackHandler
}
from
'
react-native
'
;
import
{
connect
}
from
'
react-redux
'
;
import
Drawer
from
'
react-native-drawer
'
;
import
Icon
from
'
react-native-vector-icons/MaterialIcons
'
;
...
...
@@ -41,7 +41,19 @@ const sceneToTitle = (scene) => {
};
const
ReduxNavigator
=
(
props
)
=>
{
const
{
currentScene
,
loggedIn
,
drawerOpen
,
updateDrawer
}
=
props
;
const
{
currentScene
,
loggedIn
,
drawerOpen
,
updateDrawer
,
isFirstScene
,
back
,
navigateToWelcome
}
=
props
;
BackHandler
.
addEventListener
(
'
hardwareBackPress
'
,
()
=>
{
if
(
!
isFirstScene
)
{
back
();
return
true
;
}
else
if
(
currentScene
!==
'
welcome
'
)
{
navigateToWelcome
();
return
true
;
}
BackHandler
.
exitApp
();
return
true
;
});
if
(
loggedIn
)
{
return
(
<
Drawer
type
=
"
overlay
"
...
...
@@ -100,6 +112,7 @@ ReduxNavigator.propTypes = {
isFirstScene
:
PropTypes
.
bool
.
isRequired
,
updateDrawer
:
PropTypes
.
func
.
isRequired
,
back
:
PropTypes
.
func
.
isRequired
,
navigateToWelcome
:
PropTypes
.
func
.
isRequired
,
};
const
mapStateToProps
=
state
=>
({
...
...
@@ -112,6 +125,7 @@ const mapStateToProps = state => ({
const
mapDispatchToProps
=
dispatch
=>
({
updateDrawer
:
isOpen
=>
dispatch
(
actions
.
updateDrawer
(
isOpen
)),
back
:
()
=>
dispatch
(
actions
.
back
()),
navigateToWelcome
:
()
=>
dispatch
(
actions
.
navigate
(
'
welcome
'
,
true
)),
});
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
ReduxNavigator
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment