-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30065 from sarious/fix/17866
Fix 17866: After pressing the back arrow to "Send/Request money" screen, the keyboard flashes
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// eslint-disable-next-line no-restricted-imports | ||
import {useEffect, useState} from 'react'; | ||
import {Dimensions} from 'react-native'; | ||
import {initialWindowMetrics} from 'react-native-safe-area-context'; | ||
|
||
/** | ||
* A convenience hook that provides initial size (width and height). | ||
* An initial height allows to know the real height of window, | ||
* while the standard useWindowDimensions hook return the height minus Virtual keyboard height | ||
* @returns {Object} with information about initial width and height | ||
*/ | ||
export default function () { | ||
const [dimensions, setDimensions] = useState(() => { | ||
const window = Dimensions.get('window'); | ||
const screen = Dimensions.get('screen'); | ||
|
||
return { | ||
screenHeight: screen.height, | ||
screenWidth: screen.width, | ||
initialHeight: window.height, | ||
initialWidth: window.width, | ||
}; | ||
}); | ||
|
||
useEffect(() => { | ||
const onDimensionChange = (newDimensions) => { | ||
const {window, screen} = newDimensions; | ||
|
||
setDimensions((oldState) => { | ||
if (screen.width !== oldState.screenWidth || screen.height !== oldState.screenHeight || window.height > oldState.initialHeight) { | ||
return { | ||
initialHeight: window.height, | ||
initialWidth: window.width, | ||
screenHeight: screen.height, | ||
screenWidth: screen.width, | ||
}; | ||
} | ||
|
||
return oldState; | ||
}); | ||
}; | ||
|
||
const dimensionsEventListener = Dimensions.addEventListener('change', onDimensionChange); | ||
|
||
return () => { | ||
if (!dimensionsEventListener) { | ||
return; | ||
} | ||
dimensionsEventListener.remove(); | ||
}; | ||
}, []); | ||
|
||
const bottomInset = initialWindowMetrics && initialWindowMetrics.insets && initialWindowMetrics.insets.bottom ? initialWindowMetrics.insets.bottom : 0; | ||
|
||
return { | ||
initialWidth: dimensions.initialWidth, | ||
initialHeight: dimensions.initialHeight - bottomInset, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters