Nativebase: Setting Toast style marginBottom still blocks elements below it

Created on 29 May 2019  路  7Comments  路  Source: GeekyAnts/NativeBase

Issue Description

I have a custom bottom navigation bar, and toasts with marginBottm block it.

Toast.show({
  text: "Done!",
  duration: 4000,
  style: { marginBottom: 50 }
});

My environment:

  • node: 10.15.1
  • yarn: 1.10.1
  • react: 16.6.3
  • react-native: 0.57.8
  • native-base: 2.10.0

My device:

  • not using expo or emulator
  • real device, xiaomi mi5s
  • device os: Android 9 (lineage os)

Additional info

I looked through the code and the existed closed issues: #2089 #1342 #2059.

The @SupriyaKalghatgi 's solution is kind of working at ios only, because of getTop method returning 30 pixels, as a bottom position for ToastContainer's Animated.View.

I think the proper solution wholud be:

  • or adding pointerEvents="box-none" to Animated.View
  • or adding separate prop for Animated.View styles

Workaround

Currently I using this workaround to monkey-patch ToastContainer
(I using closure at bottom option, to change it dynamically)

import { Toast } from 'native-base';

const CONTAINER_STYLE = { bottom: 0 };

export function showToast(opts, containerStyle) {
    CONTAINER_STYLE.bottom = (containerStyle && containerStyle.bottom) || 0;
    if (!Toast.toastInstance._root.patched) {
        const me = Toast.toastInstance._root;
        me.patched = true;
        me.getToastStyle = () => ({
            position: 'absolute',
            opacity: me.state.fadeAnim,
            width: '100%',
            elevation: 9,
            paddingHorizontal: 0,
            top: undefined,
            bottom: CONTAINER_STYLE.bottom,
        });
    }
    return Toast.show(opts);
}

Most helpful comment

why is this closed? same issue using native-base v2.13.8

All 7 comments

I'm also facing the same issue

same

Please check out our latest release v2.12.5.

why is this closed? same issue using native-base v2.13.8

if you allow for custom position for the Toast to show then i probably would not use the marginBottom style that's causing this issue, the top/bottom position is either blocking the mobile bottom tab menu or the top menu

same

And another same.

As far as i debugged. The problem its found on the class ToastContainer.js ln 166: this.closeModal.bind(this, reason);

That binding its not calling the function closeModal, the responsible on destrying the main container of the toast.
n-b version: 2.13.13

I had to fix it copying the library and using my patched version.

This its not closed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nschurmann picture nschurmann  路  3Comments

muthuraman007 picture muthuraman007  路  3Comments

mcpracht picture mcpracht  路  3Comments

bsiddiqui picture bsiddiqui  路  3Comments

georgemickael-b picture georgemickael-b  路  3Comments