Skip to content

Commit

Permalink
Remove blinking of Keyboard after navigating to Send Sheet (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
osdnk authored Feb 13, 2020
1 parent 31de9ca commit 7c07a6c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
31 changes: 29 additions & 2 deletions src/components/fab/SendFab.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@ import PropTypes from 'prop-types';
import React from 'react';
// import Animated from 'react-native-reanimated';
import { withNavigation } from 'react-navigation';
import { InteractionManager } from 'react-native';
import { compose, onlyUpdateForKeys, withHandlers } from 'recompact';
import { withFabSelection } from '../../hoc';
import { withFabSelection, withTransitionProps } from '../../hoc';
import { colors } from '../../styles';
import { Icon } from '../icons';
import { Centered } from '../layout';
// import DeleteButton from './DeleteButton';
import FloatingActionButton from './FloatingActionButton';
// import MovableFabWrapper from './MovableFabWrapper';

let onPressMutex = false;
/**
* This function is a bit hacky workaround for an issue of blinking
* keyboard while navigating from wallet screen to send sheet immediately
* after closing asset screen. Firstly, I guarantee that there're no
* collapsing events by mutex, then I set additional timeout with flexible
* time set in order to make sure that there's always enough time
* to close the keyboard after transition.
*/
function performSafely(operation, transitionProps) {
if (onPressMutex) {
return;
}
onPressMutex = true;
InteractionManager.runAfterInteractions(() => {
const current = Date.now();
setTimeout(() => {
operation();
onPressMutex = false;
}, Math.max(1000 - current + transitionProps.date + transitionProps.isTransitioning ? 400 : 0, 0));
});
}

const FloatingActionButtonWithDisabled = withFabSelection(FloatingActionButton);

const SendFab = ({
Expand Down Expand Up @@ -68,8 +92,11 @@ SendFab.defaultProps = {

export default compose(
withNavigation,
withTransitionProps,
withHandlers({
onPress: ({ navigation }) => () => navigation.navigate('SendSheet'),
onPress: ({ navigation, transitionProps }) => () => {
performSafely(() => navigation.navigate('SendSheet'), transitionProps);
},
}),
onlyUpdateForKeys(['disabled', 'sections'])
// withProps({
Expand Down
4 changes: 4 additions & 0 deletions src/redux/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ export const updateTransitionProps = payload => dispatch => {
const INITIAL_STATE = {
transitionProps: {
blurColor: null,
date: Date.now(),
effect: '',
isTransitioning: false,
},
};

export default (state = INITIAL_STATE, action) => {
if (action.type === UPDATE_TRANSITION_PROPS) {
if (action.payload.date) {
state.transitionProps.data = action.payload.date;
}
return {
...state,
transitionProps: {
Expand Down
8 changes: 6 additions & 2 deletions src/screens/Routes/Routes.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ import {
enableScreens();

const onTransitionEnd = () =>
store.dispatch(updateTransitionProps({ isTransitioning: false }));
store.dispatch(
updateTransitionProps({ date: Date.now(), isTransitioning: false })
);
const onTransitionStart = () =>
store.dispatch(updateTransitionProps({ isTransitioning: true }));
store.dispatch(
updateTransitionProps({ date: Date.now(), isTransitioning: true })
);

const SwipeStack = createMaterialTopTabNavigator(
{
Expand Down

0 comments on commit 7c07a6c

Please sign in to comment.