Swiftpack.co - sboko83/PageContainer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by sboko83.
sboko83/PageContainer v0.4.0
PageContainer implements a simple way to display AlertView, ActionSheetView, etc.
⭐️ 1
🕓 7 weeks ago
iOS macOS
.package(url: "https://github.com/sboko83/PageContainer.git", from: "v0.4.0")

PageContainer

Swift Package Manager compatible License: MIT

PageContainer implements a simple way to display AlertView, ActionSheetView, etc.
The page container is located at the topmost level of the view. No need to create state variables and stuff. The display is performed by calling the ViewModel methods. This is convenient when you have a lot of screens in your application, as well as when you need the view to look non-standard.
The output views can be modified using PageContainerConfig (singleton). You can change the background color, text color, buttons, frames, rounding radius, and so on.

LoadingView locks the screen and displays information in the center of the screen about what is loading.
AlertView displays information in the center of the screen: an icon, a title, text and an OK button.
Action Sheet View displays in the center of the screen: title, body (other view, optional) and an array of buttons.
Bottom Buttons View displays at the bottom of the screen: the title (optional) and an array of buttons.

README на русском языке

Requirements

  • iOS 14.0+

Installation

Swift Package Manager

In Xcode:

Manual installation

The project has no external dependencies.
If you need to add a PageContainer to another project, you need to copy the PageContainer folder to your project with the options "Copy items is needed" and "Create groups".

Examples

Common Before using it, you need to import the module.
You need to create a ViewModel and inherit it from PageContainerViewModel.
In the root View, which is responsible for the entire screen, we add the ViewModel and the PageContainer call.

import PageContainer

class TestViewModel: PageContainerViewModel {
} 
import PageContainer

struct TestPageView: View {
    @StateObject private var viewModel = TestViewModel()
    var body: some View {
        PageContainer(viewModel) {
            // <- Here is your content
        }
    }
}

LoadingView example

import PageContainer

class TestViewModel: PageContainerViewModel {
    func loadSomeData() {
        showLoading() // showing LoadingView
        networking.request { result in
            // data processing here
            self.hideLoading() // hiding LoadingView
        }
    }
}
import PageContainer

struct TestPageView: View {
    @StateObject private var viewModel = TestViewModel()
    var body: some View {
        PageContainer(viewModel) {
            Button(action: { viewModel.loadSomeData() }) {
                Text("Load data")
            }
        }
    }
}

AlertView example

import PageContainer

class TestViewModel: PageContainerViewModel {
    func outputUserInfo() {
        // possible actions and/or conditions
        showMessage(message: "User information") {
            // actions after closing AlertView
        }
    }
}
import PageContainer

struct TestPageView: View {
    @StateObject private var viewModel = TestViewModel()
    var body: some View {
        PageContainer(viewModel) {
            Button(action: { viewModel.outputUserInfo() }) {
                Text("Show user info")
            }
        }
    }
}

All usage examples are here: Demo folder

Change log

0.4

  • Added the ability to display Custom View.
  • Refactoring.
  • Editing documentation in Russian and English.
  • Demo project added.

0.3

  • The AlertView icon has been redesigned, now you can set it yourself.

GitHub

link
Stars: 1
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Version 0.4.0
7 weeks ago
  • Added the ability to display CustomView.
  • Refactoring.
  • Editing documentation in Russian and English.
  • Demo project added.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics