Giter Club home page Giter Club logo

Comments (3)

pie6k avatar pie6k commented on June 9, 2024 4

I've created some hook that disables manager while some component is rendered

import { Platform } from 'react-native';
import KeyboardManager from 'react-native-keyboard-manager';
import { useEffect } from 'react';

export function initializeKeyboardManager() {
  if (Platform.OS === 'ios') {
    KeyboardManager.setEnable(true);
    KeyboardManager.setEnableDebugging(false);
    KeyboardManager.setKeyboardDistanceFromTextField(200);
    KeyboardManager.setPreventShowingBottomBlankSpace(true);
    KeyboardManager.setEnableAutoToolbar(false);
    // KeyboardManager.setToolbarDoneBarButtonItemText('Done');
    // KeyboardManager.setToolbarManageBehaviour(0);
    KeyboardManager.setToolbarPreviousNextButtonEnable(false);
    // KeyboardManager.setShouldToolbarUsesTextFieldTintColor(false);
    // KeyboardManager.setShouldShowToolbarPlaceholder(false);
    // KeyboardManager.setShouldShowTextFieldPlaceholder(true); // deprecated, use setShouldShowToolbarPlaceholder
    KeyboardManager.setOverrideKeyboardAppearance(false);
    KeyboardManager.setShouldResignOnTouchOutside(true);
   
  }
}

export function disableKeyboardManager() {
  if (Platform.OS === 'ios') {
    KeyboardManager.setToolbarPreviousNextButtonEnable(false);
    KeyboardManager.setEnable(false);
    KeyboardManager.setEnableAutoToolbar(false);
    KeyboardManager.setToolbarPreviousNextButtonEnable(false);
    KeyboardManager.setShouldShowToolbarPlaceholder(false);
    KeyboardManager.setOverrideKeyboardAppearance(false);
  }

  return initializeKeyboardManager;
}

export function useDisableKeyboardManager() {
  useEffect(() => {
    return disableKeyboardManager();
  }, []);
}

from react-native-keyboard-manager.

JeremyBradshaw7 avatar JeremyBradshaw7 commented on June 9, 2024 1

I've refined it a bit with a helper class (typescript) to turn the manager off & on:

import KeyboardManager from 'react-native-keyboard-manager';
import { Platform } from 'react-native';

// keyboard helper class
// since we introduced this after other solutions, have to turn it on/off per screen that uses it, else it will impact globally
export default class KB {
  public static DisableManager() {
    if (Platform.OS === 'ios') {
      KeyboardManager.setToolbarPreviousNextButtonEnable(false);
      KeyboardManager.setEnable(false);
      KeyboardManager.setEnableAutoToolbar(false);
      KeyboardManager.setToolbarPreviousNextButtonEnable(false);
      KeyboardManager.setShouldShowToolbarPlaceholder(false);
      KeyboardManager.setOverrideKeyboardAppearance(false);
    }
  }
  public static EnableManager() {
    if (Platform.OS === 'ios') {
      KeyboardManager.setToolbarPreviousNextButtonEnable(true);
      KeyboardManager.setEnable(true);
      KeyboardManager.setEnableDebugging(__DEV__);
      KeyboardManager.setKeyboardDistanceFromTextField(20); // 10 default
      KeyboardManager.setEnableAutoToolbar(true);
      KeyboardManager.setToolbarPreviousNextButtonEnable(true);
      KeyboardManager.setShouldToolbarUsesTextFieldTintColor(true);
      KeyboardManager.setShouldShowToolbarPlaceholder(true);
      KeyboardManager.setOverrideKeyboardAppearance(true);
    }
  }
}

We call KB.DisableManager() from the main index file, then turn it on for specific screens:

  componentWillMount() {
    KB.EnableManager();
  }
  componentWillUnmount() {
    KB.DisableManager();
  }

This seems to work for us, so I'll close this ticket.

from react-native-keyboard-manager.

douglasjunior avatar douglasjunior commented on June 9, 2024

How are you enabling and disabling the KeyboardManager on screens?

from react-native-keyboard-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.