magicismight / react-native-root-toast

react native toast like component, pure javascript solution
MIT License
2.07k stars 404 forks source link

Account for Safe Area View #82

Open mattychen opened 6 years ago

mattychen commented 6 years ago

Toast Position should account for SafeAreaView as default.

8bitAlex commented 6 years ago

Bump. I am having this issue as well.

geminiyellow commented 5 years ago

+1

AdamDiament commented 4 years ago

Bump! (Use 60 rather than top position as a workaround)

kylebake commented 1 month ago

For anyone coming across this issue, here's how I solved it:

import Toast from 'react-native-root-toast';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

export const ToastHelper = {
  useToast: () => {
    const { top } = useSafeAreaInsets();

    return {
      showSuccessToast: (message) =>
        Toast.show(message, {
          duration: Toast.durations.LONG,
          position: Math.max(Toast.positions.TOP, top),
          animation: true,
          hideOnPress: true,
          backgroundColor: '#daf5e1',
          opacity: 1,
          textColor: 'black',
          containerStyle: {
            borderColor: '#42B362',
            borderWidth: 1,
          },
        }),
    };
  },
};
import { ToastHelper } from 'shared/ToastHelper';

const MyView = () => {
  const { showSuccessToast } = ToastHelper.useToast();

  const onSubmit = () => {
    // submit a thing
    showSuccessToast('Form submitted!')
  }

  return <View></View>
}