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
387f95ad
Commit
387f95ad
authored
Jun 16, 2017
by
Gijs Hendriksen
Browse files
Merge branch 'back-button' into 'master'
Hardware back button handling for android added See merge request
!36
parents
96809f1e
86a2c008
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/components/navigator.js
View file @
387f95ad
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