Fix 1405 handle android back button in composer (#1446)
* handle android back button in composer * improve backHandler error handling * simplify composer onClose functionality
This commit is contained in:
		
							parent
							
								
									1f60e1a748
								
							
						
					
					
						commit
						04fda0f142
					
				
					 6 changed files with 37 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -1,8 +1,19 @@
 | 
			
		|||
import {isAndroid} from 'platform/detection'
 | 
			
		||||
import {BackHandler} from 'react-native'
 | 
			
		||||
import {RootStoreModel} from 'state/index'
 | 
			
		||||
 | 
			
		||||
export function init(store: RootStoreModel) {
 | 
			
		||||
  BackHandler.addEventListener('hardwareBackPress', () => {
 | 
			
		||||
    return store.shell.closeAnyActiveElement()
 | 
			
		||||
  })
 | 
			
		||||
  // only register back handler on android, otherwise it throws an error
 | 
			
		||||
  if (isAndroid) {
 | 
			
		||||
    const backHandler = BackHandler.addEventListener(
 | 
			
		||||
      'hardwareBackPress',
 | 
			
		||||
      () => {
 | 
			
		||||
        return store.shell.closeAnyActiveElement()
 | 
			
		||||
      },
 | 
			
		||||
    )
 | 
			
		||||
    return () => {
 | 
			
		||||
      backHandler.remove()
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return () => {}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue