Giter Site home page Giter Site logo

Comments (2)

lukeramsden avatar lukeramsden commented on May 23, 2024

from react-native-toast-notifications.

lukeramsden avatar lukeramsden commented on May 23, 2024

Yes, wrapping it in a KeyboardAvoidingView does solve the issue for me. Is it worth me making a PR to implement this in the library proper or is it just better as documentation?

How I'm using the library is below in case anyone else stumbles across this.

import React, {FC, useContext, useEffect, useRef, useState} from 'react';
import Toast from 'react-native-fast-toast';
import {Icon, useTheme} from '@ui-kitten/components';
import tw from '@utils/theme';
import {KeyboardAvoidingView, Platform} from 'react-native';

type ToastCtx = React.RefObject<Toast>['current'];

const ToastContext = React.createContext(null as ToastCtx);

const ToastProvider: FC = ({children}) => {
  const theme = useTheme();
  const toastRef = useRef(null);
  const [refState, setRefState] = useState(null);

  useEffect(() => {
    setRefState(toastRef.current);
  }, []);

  return (
    <ToastContext.Provider value={refState}>
      {children}
      <KeyboardAvoidingView
        behavior={Platform.OS === 'ios' ? 'position' : undefined}>
        <Toast
          ref={toastRef}
          duration={5000}
          placement="bottom"
          offset={60}
          type="normal"
          successColor={theme['color-success-500']}
          successIcon={
            <Icon
              style={tw('w-6 h-6')}
              name="checkmark-circle-outline"
              fill={theme['text-alternate-color']}
            />
          }
          warningColor={theme['color-warning-500']}
          warningIcon={
            <Icon
              style={tw('w-6 h-6')}
              name="alert-triangle-outline"
              fill={theme['text-alternate-color']}
            />
          }
          dangerColor={theme['color-danger-500']}
          dangerIcon={
            <Icon
              style={tw('w-6 h-6')}
              name="close-circle-outline"
              fill={theme['text-alternate-color']}
            />
          }
        />
      </KeyboardAvoidingView>
    </ToastContext.Provider>
  );
};

const useToast = () => useContext(ToastContext);

export {ToastProvider, useToast};

from react-native-toast-notifications.

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.