-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Displace action button/content instead of overlaying #11
Comments
Hi @JulianKingman, thanks for the link. I agree we should follow this recommendation as closely as possible. Unfortunately there's no real way for us to know if the app has an action button or not, so we can't make it happen automatically, but I wonder if we could support some sort of redux event to broadcast how tall the snackbar is at any given point (or at least broadcast when it toggles visible/hidden). For now, there is no easy solution for you, but I do want to support this soon. I'm considering re-writing the entire module to be pure JS instead of native, and that would make this type of thing easier to support. I'll update you here when there's a change. Curious to hear your thoughts about this, too! |
What if you require manually adding the snackbar component, that way it could actually take up space on the layout, and be positioned in the right place for it? render() {
<View>
<Toolbar />
<Content>
<ActionButton />
</Content>
<Snackbar />
</View>
} |
@JulianKingman that's a good idea, but currently the Snackbar UI is implemented natively, so I don't think that would be possible without rewriting the whole thing in JS. That's something I want to do, but it's a big change and probably won't be done for a while! We could add a dummy component that simply takes up space underneath the native Snackbar, but that's hacky and may not work very well if it just pushes up all content. However, it might work if you include it in a view with just your FAB... something like this: <View>
<FloatingActionButton />
<SnackbarDummy />
</View> Android uses a Are you willing to make a PR for this? |
If you're using react-native-material-ui's ActionButton, I just sent in a pr that implements this. xotahal/react-native-material-ui#144 |
@iRoachie that's a neat workaround, but I don't think that's the right way to go about it. What about exporting a Slightly modified from the original suggestion above, it could be used like: <SnackbarAvoidingView>
<ActionButton />
</SnackbarAvoidingView> or as a HOC: render() {
const SnackbarAvoidingActionButton = withSnackbarAvoidingView(ActionButton);
return <SnackbarAvoidingActionButton />;
} |
@cooperka We'd still need a way, to notify the view when the snackbar is showing as well as the duration, and height, etc. so I'm not seeing any difference. Am I missing something? |
The difference is that |
Ah gotcha 👍 |
@cooperka Fresh off the press. https://github.com/iRoachie/react-native-snackbar-avoiding-view |
Hey, nice work! Would you mind also submitting a PR to add that as a dependency to this library, and simply export it (so people don't need to install both modules separately)? Seems like it would be common enough to want both. It's cool that your module can be used as a standalone too. |
I wonder if we could also hook it up to (optionally) automatically call |
@cooperka that sounds good actually, just wondering. Is an ActionButton the only use case that the snackbar avoids? |
Anything with the same z-index as the snackbar should move to avoid it, per material design specs (because in real life, things can't occupy the same space). The only other thing defined to have the same z-index (6) is the FAB: https://material.io/guidelines/material-design/elevation-shadows.html#elevation-shadows-elevation-android So yes, that's pretty much the only thing you need to worry about. |
@cooperka Soo my method behind doing that is to pass a ref to the SnackbarAvoidView into the options for Invalid data message - all must be length 11 Snackbar.show({
title: 'That\' right FAB, move!',
duration: Snackbar.LENGTH_LONG,
ref: this.refs.avoidingView
}) |
@iRoachie try cleaning all caches and starting fresh. I got that message before when running mismatched versions of React Native (one in JS and a different one in native code). |
@iRoachie did you end up getting it to work? |
@cooperka Sorry about that, went on the backlog for a bit. Will knock up something between now and weekend |
@cooperka , if you expose onShow and onHide events this issue have an easy solution. |
Hmm, that's an interesting idea @aMarCruz. It seems like there might be some delay using events though, which could look janky (if your FAB rises up 100 ms after the snackbar appears). It would be a decent temporary solution and I'm happy to accept a PR for it! |
@cooperka , Unfortunately I don't have enough experience on Android and know nothing about iOS, but will try to make something about this. |
The event could be fired from JS, no native code needed. Have a look at src/index.js show(). |
mmm... I'm thinking about the native "onDismiss" method of Snackbar.Callback to catch dismiss events, it works without CoordinatorLayout, by anyway I'll make a try. Thanks. |
Then we could fire some sort of |
@dantman nice suggestion, that method would be ideal if anyone is up for implementing it. |
The Snackbar's class on Android doesn't seem to have animation information, so perhaps we'll have to trick CoordinatorLayout to giving us the information we need. Possibly using CoordinatorLayout.Behavior#onApplyWindowInsets if that works. |
Material design recommends that the snackbar not overlay an action button, is it possible to do that with this package?
here: https://material.io/guidelines/components/snackbars-toasts.html#snackbars-toasts-usage
The text was updated successfully, but these errors were encountered: