Coder Social home page Coder Social logo

mijick / popupview Goto Github PK

View Code? Open in Web Editor NEW
1.1K 10.0 40.0 110 KB

Popups presentation made simple (SwiftUI)

License: MIT License

Swift 98.68% Ruby 1.32%
popup swift swift-package-manager swift5 swiftui swiftui-components swiftui-framework alert popups toast

popupview's People

Contributors

fulcrumone avatar jay-jay-lama 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

popupview's Issues

Problem with scrollable content

If in popup view there is scrollable content and it's value bigger than screen's height - we can't scroll it to the bottom
Problem cam be solved with setting view's configuration to
contentFillsWholeHeigh(true) or contentFillsEntireScreen(true)

Modification of the original view position

ScreenRecording2024-05-21at15 17 24-ezgif com-video-to-gif-converter

Issue Description

When implementing a pop-up, the view in which it is hosted is altered. The view should only be as big as its container, but when the pop-up is implemented, it shifts to the top leading position, modifying the view itself.

Steps to Reproduce

  1. Create a small view:
    • Create a view that is relatively small.
  2. Implement the pop-up:
    • Add the pop-up to the small view.

Observed Behavior

  • If the view is small, the pop-up is positioned at the top leading.
  • If the view is not small, the pop-up is centered.
  • This change does not affect the behavior of the pop-up but modifies the position of the view.

Suggested Solution

Wrap the view in a container to protect its location and size, especially if the view is small. This might be an edge case, as most developers will implement a full view to start their application, but it's worth noting that the original view is modified.

no animation on dismiss

There is no animation when dismissing a popup, which is a bit of shame as the animation on insert is great

Popup Displays Underneath Open Sheet Instead of On Top

Hello, I've been using your excellent library, and it works very well. However, I've encountered an issue: when I am in a sheet and try to display a Popup, it opens underneath the currently open sheet, whereas I would like it to appear on top. I hope you can find a solution to this problem.

Stacking on different lanes

I've encountered an issue when stacking different components on top of each other, such as SwiftUI views. This results in a weird animation glitch.

Steps to Reproduce:

  1. Popup a fullscreen view.
  2. From this fullscreen popup, popup a default bottom sheet view.

The animation behaves unexpectedly as shown in the example below.

Additional Feature Request:

It would be beneficial to have a feature that allows developers to set the priorities of popups, similar to the zIndex used internally. This would enable better control over the popup flow without requiring coordination between parts. For example:

  1. Example 1: The user is on a settings configuration screen (a fullscreen popup) and receives a message (which should appear as a top popup). The message should overlay the view.
  2. Example 2: The user receives a message on top of a fullscreen subscription paywall. The message should NOT be on top of the subscription paywall.

I would appreciate any help in resolving this issue.

Simulator Screen Recording - Traft - iPhone 14 PM 16 4 - 2024-05-18 at 21 53 43

Cant used GeometryReader

When I wrap using GeometryReader ,I got results like below image

Code Snippet

'struct BottomPopup_NoCornerRadius: BottomPopup {
    func configurePopup(popup: BottomPopupConfig) -> BottomPopupConfig { popup.cornerRadius(0) }
    func createContent() -> some View {
        GeometryReader{ geo in
            VStack(alignment: .leading, spacing: 0) {
                Text("Test")
                createTitle()
                Spacer.height(16)
                createDescription()
                Spacer.height(36)
                createButtons()
            }
            .padding(.top, 32)
            .padding(.bottom, 12)
            .padding(.horizontal, 28)
        }
        }
      
}
@FulcrumOne 

Demo:
Simulator Screenshot - iPhone 15 - 2023-12-29 at 01 55 09

Why is viewModel not deiniting with a PopupView?

I use popupView for a popup that confirms the user is leaving that screen. But the ViewModel cannot be denied when combined
with the popupView, so in the long run it will lead to memory leaks.
Screenshot 2024-03-01 at 01 09 18

PopupView seems to follow the component with the biggest width in the view?

Popup seems to follow the component with the biggest width in the view?

Screenshot 2024-01-23 at 23 25 59

it works as expected when content overflows to the next line

Screenshot 2024-01-23 at 23 27 16

Code:

`
import MijickPopupView
import SwiftUI

  struct BottomCustomPopup: BottomPopup {
      func createContent() -> some View {
          HStack(spacing: 0) {
              Text("Witaj okrutny świecie")
              Spacer()
              Button(action: dismiss) { Text("Dismiss") }
          }
          .padding(.vertical, 20)
          .padding(.leading, 24)
          .padding(.trailing, 16)
      }
      func configurePopup(popup: BottomPopupConfig) -> BottomPopupConfig {
          popup
              .horizontalPadding(20)
              .bottomPadding(42)
              .cornerRadius(16)
              .tapOutsideToDismiss(true)
              .dragGestureEnabled(true)
              .contentIgnoresSafeArea(true)
      }
  }

`

Automatically falling back to Main Thread rendering engine...

Hi, thanks for this amazing library. When I present popup view, I get below log in Xcode.
Automatically falling back to Main Thread rendering engine. This fallback comes with some additional performance
overhead, which can be reduced by manually specifying that this animation should always use the Main Thread engine.

TopPopup White Safe Area (See Screenshot)

I created the following "alert" popup, and when it displays, the safe area at the top is white, despite my background being dark. I would expect any background to be using .clear by default. As a work around, I have implemented my own PopupConfig.

Screenshot 2023-06-01 at 8 08 44 AM

Animation Glitch on FullScreen Implementation.

First of all, thank you for the amazing package!

I'm encountering an issue when using popups in combination with views that contain .edgesIgnoringSafeArea(.all). Specifically, I've noticed that when the popup has contentIgnoresSafeArea set to either true or false, the following glitches occur:

  1. Animation Glitch:

    • When the popup animation goes from bottom to top, it stops at the safe area boundary before continuing. This results in a noticeable hitch in the animation.
  2. Post-Dismissal Lag:

    • After dismissing the popup, there is an animation lag where a thin component of the view remains visible momentarily.

I would greatly appreciate any assistance in resolving this issue.


struct WebViewWrapperView: View {
    
    @Environment(\.presentationMode) private var presentation

    let title : String
    let request: URLRequest
    
    var body: some View {
        VStack {
            navigationBar
            
            titleView
            
            WebView(request: request)
        }
    }
    private var titleView : some View {
        HStack{
            Text(title)
                .modifier(Manrope40Bold())
                .fixedSize(horizontal: false, vertical: true)
                .foregroundColor(Color.black)
                .padding(.bottom, 12)
            Spacer()
        }.padding(.horizontal)
    }
    
    private var navigationBar : some View {
        return HStack {
            Button(action: {
                self.presentation.wrappedValue.dismiss() // dismiss the navigation view
                PopupManager.dismiss()
            }, label: {
                RoundButtonStyleView(buttonType: .backArrow, widthAndHeight: 36, tintColor: .gray, iconColor: .black)

            })
            Spacer()
            
            
        }
        .padding(.horizontal)
        .padding(.top, 60)
    }
}

import SwiftUI
import MijickPopupView

struct PopupFullScreen<Content: View>: BottomPopup {
    var cornerRadius: CGFloat?
    var contentIgnoresSafeArea: Bool?
    var horizontalPadding: CGFloat?
    var backgroundColor: Color?
    var content: () -> Content
    
    init(
        cornerRadius: CGFloat? = nil,
        contentIgnoresSafeArea: Bool? = nil,
        horizontalPadding: CGFloat? = nil,
        backgroundColor: Color? = nil,
        @ViewBuilder content: @escaping () -> Content
    ) {
        self.content = content
        self.cornerRadius = cornerRadius
        self.contentIgnoresSafeArea = contentIgnoresSafeArea
        self.horizontalPadding = horizontalPadding
        self.backgroundColor = backgroundColor
    }
    
    func configurePopup(popup: BottomPopupConfig) -> BottomPopupConfig {
        var modifiedPopup = popup
            .contentFillsEntireScreen(true)
            .dragGestureEnabled(false)
        if let cornerRadius = cornerRadius {
            modifiedPopup = modifiedPopup.cornerRadius(cornerRadius)
        }
        if let contentIgnoresSafeArea = contentIgnoresSafeArea {
            modifiedPopup = modifiedPopup.contentIgnoresSafeArea(contentIgnoresSafeArea)
        }
        if let horizontalPadding = horizontalPadding {
            modifiedPopup = modifiedPopup.horizontalPadding(horizontalPadding)
        }
        if let backgroundColor = backgroundColor {
            modifiedPopup = modifiedPopup.backgroundColour(backgroundColor)
        }
        return modifiedPopup
    }
    
    func createContent() -> some View {
        content()
            .frame(maxHeight: .infinity, alignment: .top)
    }
}

 private func configurePopup(_ config: GlobalConfig) -> GlobalConfig { config
        .top { $0
            .cornerRadius(24)
            .dragGestureEnabled(true)
            .tapOutsideToDismiss(true)
        }
        .centre { $0
            .tapOutsideToDismiss(false)
        }
        .bottom { $0
            .stackLimit(4)
            .tapOutsideToDismiss(true)
        }
    }

Simulator Screen Recording - Traft - iPhone 14 PM 16 4 - 2024-05-18 at 23 07 18
Simulator Screen Recording - Traft - iPhone 14 PM 16 4 - 2024-05-18 at 23 09 55

BottomPopup placed under sheet

Hi, very nice work!

I only have one issue, the BottomPopup is placed under other sheets.

So if I show a sheet, then present a BottomPopup, I have to dismiss the sheet for the BottomPopup to be visible.

UIScreen.main.bounds doesn't work for iPad and Mac

Manually computing the screen width limits the usage of the library only for the iPhone and it's not the ideal way for SwiftUI. On iPad, in split screen or with stage manager, UIScreen.main.bounds gives the width of the entire screen, not the width of the app's window.

Simulator Screenshot - iPad Pro (12 9-inch) (6th generation) - 2023-05-22 at 12 59 38

The fix is actually quite simple, mostly removing some .frame modifiers, like in this example

Screenshot 2023-05-22 at 13 00 24

And now it looks good everywhere.

Simulator Screenshot - iPad Pro (12 9-inch) (6th generation) - 2023-05-22 at 13 00 18

The background view has the same problem, more apparent on the Mac.

Screenshot 2023-05-22 at 13 27 51

But this too can be fixed quite easily

Screenshot 2023-05-22 at 13 28 10
Screenshot 2023-05-22 at 13 28 16

I can open a pull request with these changes if that's ok for you

Bug with custom center two popups

Issue Description

When attempting to .showAndStack() two separate center popups with custom views at the same time, the background view always adopts a gray color. This behavior occurs despite different configurations intended for the popups. Additionally, an issue with tap gestures is present when a bottom sheet with a TabView is used; the button tap does not work upon the first appearance.

Steps to Reproduce

  1. Implement .showAndStack() with two separate center popups with custom views.
  2. Observe that the background view is gray for both popups.
  3. Implement a bottom sheet with a TabView.
  4. Notice that the button within the TabView does not work on the first appearance.

Expected Behavior

The background view should not default to gray when stacking popups, and all user interactions, such as tap gestures on buttons within a TabView, should be responsive upon the first appearance.

Screenshots

  • iPhone 15 Example:
    iPhone 15 Example

  • iPhone 15 Pro Example:
    iPhone 15 Pro Example

  • Screenshot of Issue:
    Issue Screenshot

Code Snippet

struct BreakDownBottomSheetView: BottomPopup {

    func configurePopup(popup: BottomPopupConfig) -> BottomPopupConfig {
        popup
            .tapOutsideToDismiss(true)
            .dragGestureEnabled(true)
            .contentIgnoresSafeArea(true)
    }

    func createContent() -> some View {
        VStack(spacing: 15){
            TabView(selection: $index) {
                ForEach(yourDataArray, id: \.self) { item in
                    Button(action: {
                        // Button action here
                        // Doesn't work on first appearance
                    }) {
                        Text("Button for \(item)")
                    }
                    .tabItem {
                        Image(systemName: "some-system-image")
                        Text("Tab \(item)")
                    }
                    .tag(item)
                }
            }
            .tabViewStyle(.page(indexDisplayMode: .never))
            .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .never))
        }
    }
}

BreakDownBottomSheetView()
    .showAndStack()

DismissAfter should be tied to a specific popup

I am setting dismiss after 4 seconds for example. if the user manually dismisses the first notification and a second one is triggered, the first dismiss after 4 that was set on a previous notification seems to dismiss the current notification

Shift up the screen when the keyboard is opened.

If I have a TextEditor on the bottom popup, and the TextEditor is focused, the keyboard doesn't open. I think this is because the bottom PopupView doesn't shift up. Can we make the screen shift up when the keyboard is opened? Thanks.

Dismiss on touching outside?

Congratulations on this awesome library! The only thing missing is to dismiss the popup when touching outside. Would be great if this feature can be added.

PopupView size not updated after screen rotation.

Steps to reproduce:
1, Start the app when the phone is in portrait mode.
2, Rotate the phone to landscape mode.
3, Open the bottom PopupView.

The bottom PopupView doesn't span the full screen width. Instead, it displays a shadow strip in the center of the screen with full height.

Pod not update the latest code

pod 'Mijick_PopupView'

After pod install
I have to change
import PopView to Mijick_PopupView

but I got this error. please look that issue

Screenshot 2023-08-29 at 14 10 59

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.