Skip to content

Instantly share code, notes, and snippets.

@suciptoid
Created November 10, 2017 07:34
Show Gist options
  • Save suciptoid/a67bc9ce94eaab24133cf4d04764f777 to your computer and use it in GitHub Desktop.
Save suciptoid/a67bc9ce94eaab24133cf4d04764f777 to your computer and use it in GitHub Desktop.
Hide keyboard middleware React Native Navigation + Redux

Create Redux middleware to hide keyboard (if open) when navigating screen

// Hide keyboard middleware
const keyboardMiddleware = store => next => action => {

    // If action is navigate screen
    if(action.type == 'NAVIGATE_SCREEN'){
        Keyboard.dismiss()
    }

    return next(action)
}

Apply to your store

// Hide keyboard middleware
const keyboardMiddleware = store => next => action => {

    // If action is navigate screen
    if(action.type == 'NAVIGATE_SCREEN'){
        Keyboard.dismiss()
    }

    return next(action)
}

// Disable Logger in production
const middleware = (global.__DEV__) ? [thunk, logger] : [thunk];

export default configureStore = (initialState) => {
    return createStore(
        rootReducer,
        initialState,
        applyMiddleware(...middleware,keyboardMiddleware)
    )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment