Giter Site home page Giter Site logo

elai950 / alerttoast Goto Github PK

View Code? Open in Web Editor NEW
1.9K 12.0 170.0 11.79 MB

Create Apple-like alerts & toasts using SwiftUI

Home Page: https://elai950.github.io/AlertToast/

License: MIT License

Swift 80.74% Ruby 19.26%
swift swiftui alert popup apple toast dialog apple-music ui-components alert-controller

alerttoast's Introduction

Hi there ๐Ÿ‘‹, My name is Elai!

I'm a self-thought iOS Mobile Developer

Technology Stack: Swift / JAVA / JS / React / HTML / CSS / C++

  • ๐Ÿ”ญ Currently working as an iOS Mobile Developer in the biggest mobility company in my country.
  • โšก Hobby: Unreal Engine Game Development.

github linkedin

Lastest Blog Posts:

alerttoast's People

Contributors

barnard-b avatar coffmark avatar dqgriffin avatar egehankalayci avatar elai950 avatar lammertw avatar megakoko avatar nouun avatar ptrkstr avatar satococoa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alerttoast's Issues

SwiftUI issue "Invalid frame dimension (negative or non-finite).

Describe the bug
Xcode shows an issue when certain alerts are displayed

Screenshots
If applicable, add screenshots to help explain your problem.

Screenshot

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] iPhone 11
  • OS: [e.g. iOS8.1] iOS15.0

Additional context
Problem occurs in AlertToast/AlertToast/line 439

.

Loading Toast Cannot Be Dismissed

Describe the bug
The Loading Toast, cannot be dismissed by Clicking on The Toast but can be dismissed using the button from which the toast is popped up. All Other Toasts can be dismissed by clicking on the toast.

To Reproduce
Steps to reproduce the behavior:

  1. Implement Loading Toast
  2. Run The App and Start off the toast.
  3. Click on the spinner and it would not dismiss.

Expected behavior
I want to dismiss the loading toast by clicking on the spinner like in other toasts.

Screenshots
Sorry, No Screenshots are available at this point of time. You can ask for them later.

Desktop (please complete the following information):

  • OS: macOS Monterey 12.3.1
  • Browser: Safari
  • Version: Latest

Smartphone (please complete the following information):

  • Device: iPhone 13 Mini (Simulator)
  • OS: iOS 15 Latest
  • Browser: Safari
  • Version: Latest

Additional context
N/A

No linebreaks in subtitle?

Describe the bug
I assume it is a bug and not intention. I cannot present a message that is longer than X characters.
I am using a Banner type but it seems to behave similar with HUD too.

My assumption was that using a subtitle, it would show multiple lines and the banner would grow bigger in vertical size.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
image

Smartphone (please complete the following information):

  • Device: Simulator - iPhone 11
  • OS: iOS 15
  • Version master branch

Invalid frame dimension (negative or non-finite).

Getting this error message in Xcode 13.

Invalid frame dimension (negative or non-finite).

It's happening on this line

.frame(maxWidth: .infinity, maxHeight: alert().displayMode == .alert ? .infinity : -hostRect.midY / 2, alignment: .center)

Dismiss does not work when using .loading alert

Describe the bug
I expect to display loading alert. Once Published variable changes to different value then I'd expect new alert to display only 2 seconds, not infinite. Also tap to dismiss does not work in this case

Expected behavior
.toast(isPresenting: $showToast) { if viewModel.sendMessageResponse == .successfullySent { return AlertToast(type: .complete(.green), title: "Message Sent!", custom: .custom(backgroundColor: Color.customYellow)) } else if viewModel.sendMessageResponse == .errornousResponse { return AlertToast(type: .error(.red), title: "Unable to send message!", custom: .custom(backgroundColor: Color.customYellow)) } else { return AlertToast(displayMode: .alert, type: .loading, custom: .custom(backgroundColor: Color.customYellow)) }

Steps

  1. Change showToast to true -> this displays loading alert
  2. Waiting for async call to update sendMessageResponse to .successfullySent or .errornousResponse
  3. Alert green or red is displayed infinitely and it is impossible to to tap to dismiss success/error alert.

Popover cuts off `.hud` alert

Describe the bug
Using .hud in a popover causes the top of it to be cut off.

To Reproduce

struct ContentView: View {
    @State var showPopover = false
    @State var showToast = false
    
    var body: some View {
        Button("Show Popover") {
            self.showPopover.toggle()
        }
        .popover(isPresented: self.$showPopover) {
            List {
                Button("Show Toast") {
                    self.showToast.toggle()
                }
            }
            .toast(isPresenting: self.$showToast) {
                AlertToast(displayMode: .hud, type: .regular, title: "Test")
            }
        }
    }
}

Expected behaviour
The toast to be visible.

Screenshots
image

Toast hides behind the Navigation view

Describe the bug
When presenting AlertToast in SwiftUI view with Inline Navigation view, AlertToast with display mode (.hud) hides behind the navigation view.

To Reproduce
Steps to reproduce the behavior:

import SwiftUI
import AlertToast

struct ContentView: View {
    @State var isPresenting = true
    var body: some View {
        NavigationView {
        ZStack {
            VStack{
                Text("Hello, world!")
                    .padding()
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .toast(isPresenting: $isPresenting, duration: 2.0, tapToDismiss: true, alert: {
                
                return AlertToast(displayMode: .hud, type: .complete(.white), title: "Testing Alert Toast")
            })
        }
        .navigationTitle("Navigation Title")
        .navigationBarTitleDisplayMode(.inline)
        }
    }
}

Expected behavior
AlertToast should present in front of the navigation view.

Screenshots
IMG_5045

Smartphone (please complete the following information):

  • Device: iPhone12 Mini
  • OS: iOS14.6

AlertToast.AlertType.loading results in a crash on macOS Monterey

Describe the bug
When presenting a .toast with AlertToast.AlertType.loading on macOS Monterey, an app crashes

To Reproduce
Steps to reproduce the behavior:

  1. Apply the .toast modifier to a few
  2. Set it's type property to AlertToast.AlertType.loading and title to a string of choice
  3. Try to present the toast, for example with a button

Expected behavior
I expected the above steps to produce a toast that shows a loading indicator, like on iOS and iPadOS

Screenshots
Bildschirmfoto 2021-12-19 um 14 33 53

Desktop (please complete the following information):

  • OS: macOS 12.0 (Monterey) and up

Not usable as global modifier when sheet is presented

I tried this in my project, where Im using some views in sheets. I need some global error handling, so I used this on top level view. It cant work, because this implementation uses simple overlay over content view. Unfortunately I didnt look into the source codes before trying to integrate it... ๐Ÿ˜ž

Toast renders behind Keyboard.

Describe the bug
I'm not sure if that's possible to achieve, but when showing a toast alert while a keyboard is shown the toast renders behind it.

To Reproduce
Steps to reproduce the behavior:

  1. Create a SwiftUI View
  2. Create a textfield and Button
  3. The Button should "activate" a toast alert.
  4. Now type something in the textfield and press the button when the keyboard is shown. Here you go...

Expected behavior
I'd expect the toast to render in front of the keyboard, still I'm not sure if that's possible to achieve.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):

  • only on iOS!

Smartphone (please complete the following information):

  • Device: iPhone 11
  • OS: iOS 14.4.2

Additional context
Add any other context about the problem here.
Still thank you for the nice library.

'AlertToast' initializer is inaccessible due to 'internal' protection level

Updated to version 1.3.5 and still seeing this error message in Xcode 13.

'AlertToast' initializer is inaccessible due to 'internal' protection level

.toast(isPresenting: $showToast){
            
            AlertToast(displayMode: .hud, type: .systemImage(toastImage!, toastImageColor!), title: toastTitle, subTitle: toastSubTitle)
                
        }

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.

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

displayMode messes up my screens navigation

Here is the video of my problem. It's pretty simple. I realized that when I use displayMode: .alert everything works fine, but with any other displayMode it messes up navigation and navigation doesn't work properly. It's like it reopens the same screen and just displays toast.

I cannot figure out why. If you need further explanation I can give it to you :)

Video: https://vimeo.com/663400646

Background opacity of View when AlertToast type hud

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
I required to set my View should dim background when AlertToast type hud presented.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
I want to achieve something like below
Screenshot 2021-02-18 at 11 07 59

Issue: Swift Compiler Error when adding package

Expected Behavior

I am able to add the package and build/run my application without errors.

Actual Behavior

Once I add the package and try to build, I get "153 issues" which are all Swift Compiler Errors

Screen Shot 2021-10-26 at 7 44 44 PM

Steps to Reproduce the Problem

  1. Open XCode project and add package using Swift Package Manager
  2. Add import statement "import AlertToast"
  3. Build

Specifications

  • SwiftUI Version: 5
  • Platform (iOS or macOS): watchOS

Wrong position of toast while displaying in sheet

Describe the bug
Toast will show in wrong position with hud display mode when using it in sheet. This bug appears only in iOS

To Reproduce
Steps to reproduce the behavior:

  1. Define a view as sheet
  2. Add toast to it with hud display mode
  3. Call the toast to show

Expected behavior
The Y Position of Toast should be much more below or even below the NavigationView (if is defined)

Screenshots
IMG_0361

Smartphone:

  • Device: iPhone 12
  • OS: iOS 14.4

Sample code:

import SwiftUI
import AlertToast

struct ContentView: View {
    
    @State private var showingDetail = false
    
    var body: some View {
        Button("Show Detail") {
            showingDetail.toggle()
        }
        .sheet(isPresented: $showingDetail) {
            NextView()
        }
    }
}

struct NextView: View {
    
    @State var showToast = false
    
    var body: some View {
        ScrollView {
            Button("Show Detail") {
                showToast.toggle()
            }
            .padding()
        }.toast(isPresenting: $showToast, duration: 3, tapToDismiss: true, alert: {
            AlertToast(
                displayMode: .hud,
                type: .systemImage("checkmark.circle.fill", .green),
                title: "Test",
                subTitle: "Some message")
            
        })
    }
}

Cannot find 'AlertStyle' in scope

whenever I use AlertStyle Xcode throw "Cannot find 'AlertStyle' in scope"
I'm using 1.3.7
I tried to switch to master and decrease the version
I even tried AlertCustom and not worked
I checked this issue but nothing was helpful for my case

not display full text

Describe the bug
Line overflow, so not display full text.

Code in ContentView.swift

import SwiftUI
import AlertToast

struct ContentView: View{
    @State private var showToast = false
    var body: some View{
        VStack{
            Button("Show Toast"){
                 showAlert.toggle()
            }
        }
        .toast(isPresenting: $showToast){
            AlertToast(type: .regular, title: "Message Sent!")
        }
    }
}

Then not display full text in simulator, only "Mes..." and "Hello ..."

To Reproduce
Steps to reproduce the behavior:

  1. Add package
  2. Add sample code
  3. then, build

Expected behavior
Show full text , example "Message Sent!" and "Hello World!"

Screenshots

Desktop (please complete the following information):

  • OS: macOS Big Sur
  • Version 11.6

Simulator (please complete the following information):

  • Device: iPhone 13
  • OS: iOS 15.0

When custom AlertStyle applied image not showed

When configure AlertToast same like follow, the image not showed:


AlertToast(displayMode: .banner(.slide),
                          type: .image("icon_warning", Color.white),
                          title: "Messages may span more than one line,.",
                          style: AlertToast.AlertStyle.style(backgroundColor: Color.defaultOrangeColor,
                                                             titleColor: Color.white,
                                                             titleFont: Font.regular16))

You need to add .renderingMode(.template) when set .foregroundColor(color) to the Image in your banner view

Toast Window Not Large Enough On MacOS: The text gets truncated and replaced with "..."

Expected Behavior

I would like to be able to increase the size of the toast windows under MacOS so that the entire text can be read, either by stipulating the size of the window or having the window size automatically to the text provided.

Actual Behavior

The window is fixed-size (small) with the text truncated and replaced with "...".
This does not occur with the iOS version of my app.

Steps to Reproduce the Problem

  1. MacOS, SwiftUI app.

Specifications

  • SwiftUI Version: XCode 14.2 on Silicon Mac, targeting macOS 13.1 (and higher) - actual target macOS is 13.2.1. Swift 5 is being used.
  • Platform (iOS or macOS): macOS

Alert isn't positioning correctly under iOS 16

Describe the bug
The Alert style isn't positioning correctly under iOS 16.
AlertToast(displayMode: .alert, type: .error(.red), title: "Can't connect to server")

Screenshots
Bildschirmยญfoto 2022-07-09 um 13 57 42

Desktop (please complete the following information):

  • iOS 16 Developer Beta 3

System image not being displayed when AlertToast added to a package.

Describe the bug
When using AlertToast in a package, displaying a toast of displayMode type .alert neither a systemImage or Image are displayed.

To Reproduce
Steps to reproduce the behavior:

  1. Add AlertToast into a package. and create a SwiftUI view
  2. Set up an alert eg:
.toast(isPresenting: $showToast) {
    AlertToast(displayMode: .alert, type: .systemImage("pause.circle", .red), style: .style(backgroundColor: .black))
}
  1. Verify that the system image does not display in preview.
  2. Change to .hud type. image does display.

Expected behavior
System image should be visible.

Screenshots

Using .alert
image

Using .hud

image

Desktop (please complete the following information):

  • OS: iOS 16.4
  • Xcode Version 14.3 (14E222b)

Verified this works when displaying in a SwiftUI view in app not in a package.

runtime: SwiftUI: Invalid frame dimension (negative or non-finite).

I'm using Swift 5.5, SwiftUI with iOS 15 and getting the following warning:

AlertToast.swift: runtime: SwiftUI: Invalid frame dimension (negative or non-finite).

This is how I have it defined:

.toast(isPresenting: $showAlert, duration: 3, alert: {
    AlertToast(displayMode: .hud, type: .regular, title: self.loginMessage)
})

How can I get rid of that warning?

image

Make it easier to support multiple messages and message types

Is your feature request related to a problem? Please describe.
There is only a toast(isPresenting: Binding<Bool>...) function. It is cumbersome to add multiple messages and/or multiple message types.

Describe the solution you'd like
There should be a toast<Item>(item: Binding<Item?>...) function that allows defining the message in the item. This would be similar to several SwiftUI apis like alert(item:..). When the item changes the alert is displayed.

Describe alternatives you've considered
If we want to add multiple messages and/or have multiple message type, we must have multiple calls of toast(), or some other redundancy to allow this.

Cannot find 'AlertCustom' in scope

I am trying to add a custom background to a loading alert and I am getting these errors

Cannot find 'AlertCustom' in scope and Extra argument 'custom' in call

import AlertToast

...

let alertCustomisation = AlertCustom(
    backgroundColor: Color("primary"),
    titleColor: Color.red,
    subTitleColor: Color.red
)

@Published var loading = AlertToast(type: .loading, title: "", custom: alertCustomisation)

Invalid frame dimension (negative or non-finite).

Describe the bug
Invalid frame dimension (negative or non-finite).

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: iOS

Smartphone (please complete the following information):

  • Device: iPhone 11
  • OS: iOS 15 beta 6

Blur Background

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I would very like to have an blurred background

Describe the solution you'd like
A clear and concise description of what you want to happen.

When displayMode is set to .hud, the background of the complete view should be blurred

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Making a manual blur

Additional context
Add any other context or screenshots about the feature request here.

Swipe to dismiss toast

Is your feature request related to a problem? Please describe.
At the moment it is only possible to dismiss a toast by tapping on it.

Describe the solution you'd like
It would be nice if we could dismiss it by swiping (up|down) depending on where it is located on the screen.

Default alert width is too small to show message

Describe the bug
The width of the toasts seems to be fixed. When using the default toast with the default text, there is space to show only 3 characters. The width does not expand depending on text size.

To Reproduce

  1. Use the following toast:
import SwiftUI
import AlertToast

struct ContentView: View {
    @State private var showToast = false
    
    var body: some View{
        VStack{
            Button("Show Toast"){
                 showToast.toggle()
            }
        }
        .toast(isPresenting: $showToast){
            AlertToast(type: .regular, title: "Message sent!")
        }
    }
}
  1. Launch App on simulator
  2. Click the button "Show Toast"

Expected behavior
The toast should show "Message sent!".

Screenshots
See this image

Smartphone (please complete the following information):

  • Device: [Simulator iPhone 13 Pro and real iPhone 10]
  • OS: [iOS15.4]

Additional context
Semi-fixed the problem on the HUD view by adding:

///HUD View
public var hud: some View{
    Group{
        HStack(spacing: 16){
            switch type{
            case .complete(let color):
                Image(systemName: "checkmark")
                    .hudModifier()
                    .foregroundColor(color)
            case .error(let color):
                Image(systemName: "xmark")
                    .hudModifier()
                    .foregroundColor(color)
            case .systemImage(let name, let color):
                Image(systemName: name)
                    .hudModifier()
                    .foregroundColor(color)
            case .image(let name, let color):
                Image(name)
                    .hudModifier()
                    .foregroundColor(color)
            case .loading:
                ActivityIndicator()
            case .regular:
                EmptyView()
            }
            
            if title != nil || subTitle != nil{
                VStack(alignment: type == .regular ? .center : .leading, spacing: 2){
                    if title != nil{
                        Text(LocalizedStringKey(title ?? ""))
                            .font(style?.titleFont ?? Font.body.bold())
                            .multilineTextAlignment(.center)
                            .textColor(style?.titleColor ?? nil)
                    }
                    if subTitle != nil{
                        Text(LocalizedStringKey(subTitle ?? ""))
                            .font(style?.subTitleFont ?? Font.footnote)
                            .opacity(0.7)
                            .multilineTextAlignment(.center)
                            .textColor(style?.subtitleColor ?? nil)
                    }
                }
            }
        }
        .padding(.horizontal, 24)
        .padding(.vertical, 8)
        // ===========================================
        // Adding a minWidth of 200, but it is still not auto sizing depending on text size.
        // ===========================================
        .frame(minWidth: 200, minHeight: 50)
        .alertBackground(style?.backgroundColor ?? nil)
        .clipShape(Capsule())
        .overlay(Capsule().stroke(Color.gray.opacity(0.2), lineWidth: 1))
        .shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 6)
        .compositingGroup()
    }
    .padding(.top)
}

Is there any way to set the toast always on the top of screen, instead of on the center of view

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Update the animation property in SwiftUI 3 (Xcode 13)

Describe the bug
A clear and concise description of what the bug is.

'animation' was deprecated in macOS 12.0: Use withAnimation or animation(_:value:) instead.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Menu style wanted

The swiftUI default Menu style is very restrict, it is hard to custom the content style. And I find that all the open source toast don't have it.
I am a product manager learning swiftUI, so is it possible to add custom view for menu like style, and click the button shows the content view.
My thinking is pass the location of the clicked button and show the toast with the location in the toast?
Thank you so much.

tvOS compatibility possible?

Is your feature request related to a problem? Please describe.
It's not really a problem but I'm just porting my iOS app to tvOS and I was surprised that this library doesn't work on tvOS. Is there any specific reason for that?

Describe the solution you'd like
To be able to use this lib on tvOS apps.

Describe alternatives you've considered
Only other solution is to not use AlertToast on tvOS and build the view in a different way.

Additional context
I just finished porting my Android app to iOS so some of the Apple stuff is still new to me. If it is obvious why this lib can't work on tvOS I'm sorry for creating this ticket.

Long Subtitle text doesn't correctly wrap in DisplayMode "hub" or "banner"

Describe the bug
When using a long Subtitle and in DisplayMode "hub" or "banner" the subtitle doesn't wrap correctly and cuts off on both sides left and right

To Reproduce
Steps to reproduce the behavior:

The following code will demonstrate the issue

AlertToast(displayMode: .alert,
		type: .regular,
		title: "Sample Message",
		subTitle: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec gravida eleifend scelerisque. Donec ornare malesuada orci, nec tempus massa lacinia non.\n\nMaecenas sit amet convallis orci. Aenean malesuada lacus sed odio pulvinar elementum non a tellus. Etiam cursus erat sed fermentum lobortis. Phasellus feugiat euismod orci. Donec ultrices fringilla fringilla.")

Expected behavior
The text should be displayed the same way it does with DisplayMode "alert".

Screenshots

image
This is the toast using "hud"

image
This is the toast using "alert"

Smartphon:

  • Device: iPhone 14
  • OS: 16.3

toast<Item>(item: Binding<Item?>, content: (Item) -> AlertToast) modifier

iOS 15.5 removed the alert<Item>(item: Binding<Item?>, content: (Item) -> Alert) modifier which was super useful to construct an Alert based on the item wrapped by the Binding.

the replacement alert(isPresented: Bool) variants are not as powerful.

It would be really cool to add the item based modifier to AlertToast to enable a straight forward replacement. I can attempt to build it if there is interest and nobody else is working on it.

The subtitle line gets cut off on iOS banners

Describe the bug
Banner subtitle line goes off the screen instead of wrapping to the next line on iOS

To Reproduce
Steps to reproduce the behavior:

  1. Make a long subtitle in an iOS banner
  2. Observe the subtitle gets cut off

Expected behavior
The subtitle should wrap to the next line

Screenshots
Screenshot 2023-03-28 at 4 12 58 PM

Smartphone (please complete the following information):

  • Device: iPhone 14 Pro simulator
  • OS: iOS 16.2
  • Version 1.3.9

Toast truncated when it is presented from a sheet

Describe the bug
Toast truncated when it is presented from a sheet when using swiftui
CleanShot 2021-12-20 at 16 54 39@2x

To Reproduce
Steps to reproduce the behavior:

  1. Open a screen as a sheet (not full cover)
  2. Trigger the toast from a button
  3. Top portion of toast is been truncated

Expected behavior
Full toast must be visible

Desktop (please complete the following information):

  • OS: [e.g. iOS] 15.0

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

No such module AlertToast

I try to install manually AlertToast as per instructions, but I got error "No such module AlertToast" in Xcode 12.4.
Is there way to fix this?

Toast can become stuck open if it is re-shown before it completely fades out.

Describe the bug
Showing the toast after it starts fading out causes it to become stuck open.

To Reproduce
Steps to reproduce the behavior:

  1. Attach the variable used for the toast isPresented to a button.
  2. Click the button.
  3. When the toast starts fading out, click the button again.

Expected behavior
The toast fades back in and automatically fades back out at the end of the expected show duration.

Actual behavior
The toast fades back in and remains shown until it is manually dismissed by tapping it.

Screenshots
AlertToast-toast-stuck

Additional context
The issue is caused by the dismiss delay being set in onAppear, which is not called unless the view has completely faded out before it fades back in.

I was able to solve the issue in iOS 14/macOS 11 using onChange(of:) instead of onAppear (see this commit). However, onChange(of:) is not available in iOS 13 so I am not sure this is the solution you would want to use.

Sample Code

struct ContentView: View {
    
    @State var showToast = false
    
    var body: some View {
        Text("Hello, world!")
            .padding()
            .toast(isPresenting: $showToast) {
                AlertToast(type: .complete(.green))
            }
        
        Spacer()
            .frame(height: 150)
        
        Button(action: { showToast = true }) {
            Text("Press Me!")
        }
        
    }
}

Alert can never be dismissed

This is a really cool framework but I am having problem dismissing the alert if I set duration greater than 2.0. Default setting works as expected.

This works perfectly (view diasappears after 2 seconds):

.toast(isPresenting: RM.$pendingNotifications) {
                AlertToast(displayMode: .hud, type: .systemImage("exclamationmark.triangle.fill", Color.orange), title: "alert alert alert")
            }

The code below does not work. With any duration above 2.0 the view appears and never disappears. It stays on top of the screen. Tap to dismiss also does not work. I also cannot influence anything with tapToDismiss:

.toast(isPresenting: RM.$pendingNotifications, duration: 3.0) {
                AlertToast(displayMode: .hud, type: .systemImage("exclamationmark.triangle.fill", Color.orange), title: "alert alert alert")
            }

RM is an observable object exposed to the environment and pendingNotifications is @published variable.

Create Example Project

I checked both article and project. No example project. I would recommend adding project used to create demo screens.

Toaster not clearing on first call

Description
When the initial call to AlertToast is made, it does not clear after the default 2 seconds. Subsequent calls to AlertToast do properly clear after the duration.

This is only a problem when using the .hud and .banner display modes, setting displayMode: .alert works fine.

To Reproduce

  1. Submit login form with invalid entries
  2. toaster displays and remains until tapped
  3. subsequent submissions display toaster and clear after the default duration

Smartphone:

  • Device: Xcode simulator iPhone 12 and actual iPhone 12 device
  • OS: iOS 15.2.1

Code

final class SessionManager: ObservableObject {
...
    @Published var toastShow = false
    @Published var toaster = AlertToast(type: .regular) {
        didSet{ toastShow.toggle() }
    }
...
    func signIn(email: String, password: String) {
        Amplify.Auth.signIn(username: email, password: password)
            .resultPublisher
            .sink {
                if case let .failure(authError) = $0 {
                    DispatchQueue.main.async {
                        self.toaster = AlertToast(
                            displayMode: .hud,
                            type: .error(.red),
                            title: "Login Error",
                            subTitle: authError.errorDescription
                        )
                    }
                }
            }
            ....
}

@main
struct Auth2App: App {
  @StateObject var sessionManager = SessionManager.shared

    var body: some Scene {
        
        WindowGroup {
            switch sessionManager.authState {
            case .signIn:
                LoginView()
                    .environmentObject(sessionManager)
                    .toast(isPresenting: $sessionManager.toastShow){
                        sessionManager.toaster
                    }
...
}

Alert Toast (.hud display mode) is displayed behind the navigation bar items

Describe the bug
If there is a navigation bar item that has a long text, the .alert toast will be displayed behind it

To Reproduce
Steps to reproduce the behavior:

  1. Create a view with a NavigationView
  2. Add a navigation bar item with a long text to the trailing position (example: Add to favorite)
  3. Trigger an .hud AlertToast

Expected behavior
The AlertToast should be on top of the navigation bar items

Screenshots
Simulator Screen Shot - iPhone 13 - 2021-11-14 at 14 50 24

Smartphone:

  • Device: iPhone 13
  • OS: iOS 15
  • Version: 1.3.7

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.