Giter VIP home page Giter VIP logo

customalert's People

Contributors

divadretlaw 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

customalert's Issues

Teamd id on pipeline

Hi i'm trying to build an app on a pipeline and is giving me this error

Signing for "CustomAlert_CustomAlert" requires a development team. Select a development team in the Signing & Capabilities editor.

and i think id in the demo section of the library.

how can i change the team id on the library?

Textfield disabled

When adding a text field on the alert (both body and actions) the field cannot be selected. Am I missing something?

BTW, amazing project!

Alert does not get updated title when using variable

I used the demo to show the issue, alert shows empty text, only second opening has correct value. For now i delay showing the alert so gets new value but seems a bit hacky, any solution? The native Alert() has no issue.

struct SimpleAlerts: View {
    @State private var showNative = false
    @State private var showCustom = false
    
    @State var text = ""
    
    var body: some View {
        Section {
            Button {
                showNative = true
            } label: {
                Text("Native Alert")
            }
            .alert("Native Alert", isPresented: $showNative) {
                Button(role: .cancel) {
                    
                } label: {
                    Text("Cancel")
                }
            } message: {
                Text("Some Message")
            }
            
            Button {
                showCustom = true
                text = "text"
            } label: {
                Text("Custom Alert")
            }
            .customAlert("Custom Alert", isPresented: $showCustom) {
                Text(text)
            } actions: {
                Button(role: .cancel) {
                    
                } label: {
                    Text("Cancel")
                }
            }
        } header: {
            Text("Simple")
        }
    }
}

Can it support alert alignment?

  1. I want my CustomAlert to be positioned at the bottom. How can I do this? : )
  2. Is it possible to support closing the Alert by clicking on the background?
    Thank you for providing such a useful library, I'm very grateful.

Unable to get focus for a text field in iOS 17 Simulators

Hi David (or anyone contributing to this repo),

Since upgrading to Xcode 15 I have noticed an issue, but couldn't figure out the underlying cause. I wonder if you experienced anything similar?

Environment

  • Xcode 15.0 (15A240d)
  • Simulator iPhone 14, iOS 17.0

Repro Steps

  1. Create a project with SwiftUI view, add a button to trigger boolean state variable to display the view.
  2. Add multiline text view (see code snippet below) to the custom alert.
  3. Run XCUITest or just manually trigger custom alert display, make sure keyboard is setup correctly in simulator (can be tested by creating a plain TextField view and tapping into it, you should be able to type in it).
  4. Attempt to tap into multiline text field and type text. It is unresponsive to both user interactions and .tap() or .typeText(..) XCUITest methods.

Notes

  1. Same code worked in simulator and UI tests on iOS 16 simulators with no issues.

Sample alert snippet:

.customAlert(isPresented: $isInsideCommenting) {
            // MARK: Inside Commenting on Action
            Text("Action Comment")
                .font(.subheadline)
                .padding(.bottom, 4)
            getMultilineTextField("Comment for \(viewModel.action.name ?? "")", $insideComment)
        } actions: {
            /// Inside Commenting Popup Buttons
            MultiButton {
                Button("Cancel", role: .cancel) {
                    insideComment = viewModel.comment
                    isInsideCommenting = false
                }
                Button("OK") {
                    let sanitisedComment = insideComment.trimmingCharacters(in: .whitespacesAndNewlines)
                    if sanitisedComment.isEmpty {
                        viewModel.deleteComment()
                    } else {
                        viewModel.addComment(insideComment)
                    }
                    commentRecorded?()
                    isInsideCommenting = false
                }
            }
        }

Sample multiline text field constructor method:

@ViewBuilder
    func getMultilineTextField(_ title: String,
                               _ stringValue: Binding<String>) -> some View {
        if #available(iOS 16.0, *) {
            TextField(title, text: stringValue, axis: .vertical)
                .lineLimit(5, reservesSpace: true)
                .textFieldStyle(.roundedBorder)
                .multilineTextAlignment(.leading)
                .accessibilityLabel("TextFieldInAlert")
        } else {
            // Fallback on earlier versions
            TextField(text: stringValue) {
                Text(title).multilineTextAlignment(.leading)
            }.accessibilityLabel("TextFieldInAlert")
        }
    }

EnvironmentObject not working in parent view

Thanks for the effort building a custom alert, much appreciated.

There is an error when you have an EnvironmentObject in the parent view; when you activate the alert, the parent view loses access to the EnvironmentObject.

Cheers

Button doesn't seem to get updates when there's a textfield in alert content

Hi, thank you for the great framework. I run into some issues where the alert buttons didn't get updated. Here's the code:

      .customAlert("Enter access code",
                     isPresented: $isShowingAccessCodeAlert,
                     content: {
            TextField("Access Code", text: $accessCode)
                .onSubmit {
                    submitCode()
                    isShowingAccessCodeAlert = false
                }
        }, actions: {
            MultiButton {
                Button(role: .cancel) {
                } label: {
                    Text("Cancel")
                }
                
                Button("Submit", action: submitCode)
                    .disabled(accessCode.trimmingCharacters(in: .whitespacesAndNewlines).count == 0)
                    .bold()
            }
        })

it doesn't seem like the button disable state is getting updated when the user starting to enter text. What did I do wrong? Thanks!

Localize Text, Content & Buttons

Currently I need to do something like the following to get the localized text for the alert:

extension String {
  func getLocalizedTextForAlert() {
        let path = Bundle.main.path(forResource: "ar", ofType: "lproj")
        let bundle = Bundle(path: path!)
        return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
  }
}

where ar is one of the supported languages in my app (Arabic), because doing just: Text("some text") will always fallback to the English version of the some text text. Giving that I have two Localizable.strings files in the app: one for en and the other for ar localization.

Support Binding Object support for presenting similar to sheet modifier

In the current swiftui sheet that has a modifier that take a binding item as parameter and shows the sheet when the parameter is not nil. It would be very helpful if there is a way to use similar behavior on this library. BTW Thanks a lot for this awesome and handly library

For example:

.sheet(item: $deleteConfirmation, content: { item in })

Latest release bug: pressing on buttons not working all the times

I noticed that in the latest release I have to press the buttons really long to get an effect.

If I press them normally, no button callback is triggered, the alert just disappears.

I believe it was introduced by 3.5.0.

3.3.0 I am unable to install (does not resolve in Xcode).

On 3.1.0 I am unable to reproduce.

My code to show an alert:

.customAlert(confirmationSubtitle, isPresented: $showSelectionConfirmaionAlert) {
   // view code with labels and image
} actions: {
   Button("test 1") {
      // only called when long-pressing button
   }

   Button("test 2") {
      // only called when long-pressing button
   }
}

Duplicate components

I use customAlert view modifier like that:

.customAlert("Some Fancy Alert", isPresented: $restoring) {
Text("I'm a custom Message")
.font(.custom("Noteworthy", size: 24))

        ProgressView()
            .progressViewStyle(.circular)

    } actions: {
        Button(role: .cancel) {
            // some Action
        } label: {
            Text("Cancel")
        }

Simulator Screen Shot - iPhone 14 Pro - 2023-06-28 at 02 51 41

    }

Add the result is just like attachment.

Cannot auto alert when isPresented init true

Use SwiftUI API can auto alert when page first loaded, but your code cannot.

SwiftUI API code:
@State private var showAlert = true
VStack(spacing: 0) {
Text("首次启动弹出弹窗")
}
.alert("title", isPresented: $showAlert, actions: {
Button("取消", role: .cancel, action: {})
}, message: {
Text("Message")
})

Your code:
@State private var showAlert = true
VStack(spacing: 0) {
Text("首次启动弹出弹窗")
}
.customAlert("Some Fancy Alert", isPresented: $showAlert) {
Text("I'm a custom Message")
.font(.custom("Noteworthy", size: 24))
Image(systemName: "swift")
.resizable()
.scaledToFit()
.frame(maxHeight: 100)
.foregroundColor(.blue)
} actions: {
Button {
// some Action
} label: {
Label("Swift", systemImage: "swift")
}
Button(role: .cancel) {
// some Action
} label: {
Text("Cancel")
}
}

Run multiple times before displaying

When I trigger the alert, It runs 3 times every time. When I click an action button, it is supposed to display an error message. I have to click the action button 2 times before it shows and every time I click that button it runs the alert 2 times instead of 3. I would like to know If I'm doing something wrong.

backward overlay

Are you thinking of a backward overlay removal option feature in the future ?

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.