Skip to content

Commit

Permalink
[Android] Handle back button on modals
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolemos committed Mar 23, 2019
1 parent 804f265 commit 8c9ba3c
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/components/src/components/modals/ModalRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react'
import { Dimensions, SafeAreaView, StyleSheet, View } from 'react-native'
import React, { useEffect } from 'react'
import {
BackHandler,
Dimensions,
SafeAreaView,
StyleSheet,
View,
} from 'react-native'

import { ModalPayloadWithIndex } from '@devhub/core'
import { config, useTransition } from 'react-spring/native'
Expand Down Expand Up @@ -77,6 +83,25 @@ export function ModalRenderer(props: ModalRendererProps) {
const wasSettings = usePrevious(isSettings)

const closeAllModals = useReduxAction(actions.closeAllModals)
const popModal = useReduxAction(actions.popModal)

useEffect(() => {
if (!(BackHandler && BackHandler.addEventListener)) return

const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
() => {
if (!!currentOpenedModal) {
popModal()
return true
}
},
)

return () => {
backHandler.remove()
}
}, [!!currentOpenedModal])

const immediate =
sizename === '1-small' &&
Expand Down

0 comments on commit 8c9ba3c

Please sign in to comment.