Comments (6)
This is actually how AlertToast works. By receiving the Y position in the current view.
Do not put '.toast' on Button, implement it on ViewBuilder, like Group.'.sheet' can be on a button but it's not the same case for AlertToast.
This doesn't solve the problem, I have put the toast above the VStack in a Sheet, but the position still incorrect as @Rminsh showed.
from alerttoast.
I've released a new version where you can manually offset the height until I'll find a better solution.
.toast(isPresenting: ...., offsetY: CGFloat)
Closing issue.
from alerttoast.
The .toast
modifier should always be at the top of all view builders.
Add a view builder (for example VStack) then implement the .toast
on the vstack after the .sheet
modifier.
Try this:
var body: some View {
VStack{
Button("Show Detail") {
showingDetail.toggle()
}
}
.sheet(isPresented: $showingDetail) {
NextView()
}
//Implement `.toast` here
}
from alerttoast.
The
.toast
modifier should always be at the top of all view builders.
Add a view builder (for example VStack) then implement the.toast
on the vstack after the.sheet
modifier.
Try this:var body: some View { VStack{ Button("Show Detail") { showingDetail.toggle() } } .sheet(isPresented: $showingDetail) { NextView() } //Implement `.toast` here }
If I implement toast modifier in the Parent View, the toast will show up behind my sheet like this:
import SwiftUI
import AlertToast
struct ContentView: View {
@State var showToast = false
@State private var showingDetail = false
var body: some View {
Button("Show Detail") {
showingDetail.toggle()
}
.sheet(isPresented: $showingDetail) {
childView
}
.toast(isPresenting: $showToast, duration: 3, tapToDismiss: true, alert: {
AlertToast(
displayMode: .hud,
type: .systemImage("checkmark.circle.fill", .green),
title: "Test",
subTitle: "Some message")
})
}
var childView: some View {
ScrollView {
Button("Show Detail") {
showToast.toggle()
}
.padding()
}
}
}
So the correct way is to implement toast in the Child view and the Y Position should be based on the current view
from alerttoast.
This is actually how AlertToast works. By receiving the Y position in the current view.
Do not put '.toast' on Button, implement it on ViewBuilder, like Group.
'.sheet' can be on a button but it's not the same case for AlertToast.
from alerttoast.
...same here, this does not solve the problem (iOS 14.6)
It seems that .hud
has a problem.
As Rminsh wrote "...to implement toast in the Child view..." works but unfortunately not for .hud
.
What is the solution for .sheet
and the need for a .hud
type alert ??
from alerttoast.
Related Issues (20)
- Cannot find 'AlertStyle' in scope HOT 1
- No linebreaks in subtitle? HOT 9
- Toaster not clearing on first call HOT 5
- Background opacity of View when AlertToast type hud HOT 3
- Default alert width is too small to show message HOT 5
- Loading Toast Cannot Be Dismissed HOT 1
- toast<Item>(item: Binding<Item?>, content: (Item) -> AlertToast) modifier HOT 2
- Alert isn't positioning correctly under iOS 16 HOT 1
- tvOS compatibility possible? HOT 1
- Swipe to dismiss toast HOT 1
- If type is .loading, its background parent view is still clickable HOT 2
- No toast! Have implemented per instructions, but the AlertToast() does not respond with any visualisation. Have traced that it gets called, but nothing happens on screen. - Xcode 14.2, SwiftUI, iOS 16.2, Simulator and physical device. HOT 1
- Long Subtitle text doesn't correctly wrap in DisplayMode "hub" or "banner" HOT 6
- Toast Window Not Large Enough On MacOS: The text gets truncated and replaced with "..."
- Popover cuts off `.hud` alert HOT 5
- Create Example Project HOT 1
- The subtitle line gets cut off on iOS banners HOT 1
- Not usable as global modifier when sheet is presented HOT 7
- Is there any way to set the toast always on the top of screen, instead of on the center of view HOT 1
- System image not being displayed when AlertToast added to a package.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alerttoast.