• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 3 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Swift Popup Module help you popup your custom view easily. Support three way to popup, Drawer, Dialog and BottomSheet.

JFPopup

Version License Platform Language Support

JFPopup is a Swift Module help you popup your custom view easily.

Support 3 way to popup, Drawer, Dialog and BottomSheet.

Installation

cocoapods

pod 'JFPopup', '1.5.4'

Swift Package Manager

After 1.5.4

https://github.com/JerryFans/JFPopup.git

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Toast Style Support iPhone 14 Pro+ Dynamic Island(灵动岛)

Quick Create your popup view

Dialog

对话框模式,类似UIAlertConroller, 你也可以编写你的自定义AlertView

self.popup.dialog {
            let v = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
            v.backgroundColor = .red
            return v
        }

Drawer

抽屉模式,支持左右抽屉,宽度自定义,最大可以全屏,

//default left
self.popup.drawer {
            let v = DrawerView(frame: CGRect(x: 0, y: 0, width: CGSize.jf.screenWidth(), height: CGSize.jf.screenHeight()))
            v.closeHandle = { [weak self] in
                self?.popup.dismiss()
            }
            return v
        }

self.popup.drawer(with: .right) {
            let v = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: CGSize.jf.screenHeight()))
            v.backgroundColor = .red
            return v
        }

Bottomsheet

类似Flutter Bottomsheet, 底部往上弹出一个容器。 你也可以给予此创建你的个人自定义风格UIActionSheet. 底下有微信风格的组件已封装

self.popup.bottomSheet {
            let v = UIView(frame: CGRect(x: 0, y: 0, width: CGSize.jf.screenWidth(), height: 300))
            v.backgroundColor = .red
            return v
        }

通用组件

  • v1.0,暂时只有一款微信风格ActionSheet, 基于上面bottomSheet打造,后续会基于上面基础popup,打造更多基础组件

  • v1.1 新增JFToastView, 支持多种Toast

  • v1.3 新增Loading 样式弹窗, 支持多种格式,详情看下面

  • v1.4 新增微信 AlertView 样式弹窗, 支持多种格式,详情看下面

  • v1.5 JFToastView 支持iPhone14 Pro系列 灵动岛 (Toast Style Support iPhone14 Pro + Dynamic Island)

  • v1.5.2 修复偶现可能无法获取顶层keywindow导致的问题

  • v1.5.3 修复连续触发Loading show and hide偶现无法移除View的问题

AlertView

1、默认风格,自带取消按钮

JFPopupView.popup.alert {[
            .title("温馨提示"),
            .subTitle("我是默认风格,自带取消按钮"),
            .confirmAction([
                .text("知道了"),
                .tapActionCallback({
                    JFPopupView.popup.toast(hit: "我知道了")
                })
            ])
        ]}

2、Title 和 SubTitle可以二选一,不要Cancel

 JFPopupView.popup.alert {[
            .subTitle("我是Title 和 SubTitle可以二选一,单个按钮"),
            .showCancel(false),
            .confirmAction([
                .text("知道了"),
                .tapActionCallback({
                    JFPopupView.popup.toast(hit: "我知道了")
                })
            ])
        ]}

3、自定义颜色、不用动画等

JFPopupView.popup.alert {[
            .title("不同标题颜色"),
            .titleColor(.red),
            .withoutAnimation(true),
            .subTitle("我是完全自定义的,标题颜色,action颜色,文本都支持修改,不带动画"),
            .subTitleColor(.black),
            .cancelAction([.textColor(.blue),.text("我是取消超出文本裁切"),.tapActionCallback({
                JFPopupView.popup.toast(hit: "点击了取消")
            })]),
            .confirmAction([
                .text("我是确定"),
                .textColor(.red),
                .tapActionCallback({
                    JFPopupView.popup.toast(hit: "点击了确定")
                })
            ])
        ]}

4、也可以Present到VC 效果一样

//self 是 UIViewController
 self.popup.alert {
            [.title("我是从VC Present 出来的"),
             .subTitle("用法和View一致,只是一个是self.popup.alert(self是UIViewControll),一个是JFPopupView.popup.alert"),
             .confirmAction([
                .text("知道了"),
                .tapActionCallback({
                    JFPopupView.popup.toast(hit: "知道了")
                })
             ])
            ]
        }

Loading

1、only loading icon

JFPopupView.popup.loading()
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            JFPopupView.popup.hideLoading()
        }
        
 2、 loading + hit
 
 JFPopupView.popup.loading(hit: "正在载入视频")
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            JFPopupView.popup.hideLoading()
        }
        
 3、 loading in view (default in keywindow)
 
 //只支持 controller.view, 默认keywindow
        JFPopupView.popup.loading(hit: "加载中", inView: self.view)
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            JFPopupView.popup.hideLoading()
        }


Toast

已适配iPhone 14 Pro系列 灵动岛 (support dynamic island toast)

1、only hit

JFPopupView.popup.toast(hit: "普通toast,默认superview可以响应")

2、 hit + icon (内置success和fail, 支持自定义)

JFPopupView.popup.toast(hit: "支付成功", icon: .success)


JFPopupView.popup.toast(hit: "自定义Icon", icon: .imageName(name: "face"))

3、完全自定义

JFPopupView.popup.toast {
            [
                .hit("不响应super view,带背景色,加大时长,不用动画,在当前view弹出,position top"),
                .enableUserInteraction(true),
                .bgColor(UIColor.jf.rgb(0x000000,alpha: 0.3)),
                .autoDismissDuration(.seconds(value: 3)),
                .mainContainer(self.view),
                .withoutAnimation(true),
                .position(.top)
            ]
        }

ActionSheet

self.popup.actionSheet {
            [
                JFPopupAction(with: "拍摄", subTitle: "照片或视频照片", clickActionCallBack: { [weak self] in
                    self?.pushVC()
                }),
                JFPopupAction(with: "从手机相册选择", subTitle: nil, clickActionCallBack: {

                }),
                JFPopupAction(with: "用秒剪制作视频", subTitle: nil, clickActionCallBack: {

                }),
            ]
        }

VC模式创建

此方法推荐兼容OC情况下使用,或者你的popup View代码量非常大 需要一个vc来管理。

继承写法 (类似继承UITableView,dataSoure写在内部)

var config = JFPopupConfig.bottomSheet
        config.isDismissible = false
        let vc = TestCustomViewController(with: config)
        vc.show(with: self)

闭包写法

var config = JFPopupConfig.dialog
        config.bgColor = .clear
        let vc = JFPopupController(with: config, popupProtocol: self) {
            let view: UIView = {
                let view = UIView()
                view.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
                view.layer.cornerRadius = 12
                view.backgroundColor = .black
                return view
            }()
            return view
        }
        vc.show(with: self)

Author

JerryFans, [email protected]

License

JFPopup is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

mars_xlog_decoder_gui

Base On Tencent Mars Xlog Decode GUI
C++
102
star
2

JFHeroBrowser

A simplest & base on protocol & swifty way to browse photo or video with hero animation.
Swift
42
star
3

TinyPNG4Flutter

A TinyPNG Compress Image Desktop GUI For Flutter. Support macOS and windows.
Dart
27
star
4

icloud_kv_storage

A Key Value Storage Flutter Plugin Sync multiple iOS & Mac Devices base on iCloud.
Dart
16
star
5

DragAndDropKit

A Simple way help you drop or drag your source (like UIImage) between different App.
Swift
15
star
6

JFDynamicLottie

JFDynamicLottie is a Swift Lottie Extension which can dynamic replace Lottie resource like image、text and with high performance running Lottie animation.
Swift
15
star
7

file_drag_and_drop

A flutter deskstop package that allows you to drag the native file into app support.
Dart
13
star
8

flutter_auth_code_textfield

A custom auth code textfield widget.
Dart
12
star
9

xlog_ios_demo

Tencent mars xlog iOS demo
C++
12
star
10

GradientLabelDemo

Swift
9
star
11

sign_in_apple

A flutter sign in apple plugin project.
Dart
8
star
12

flutter_tiktoken

flutter_tiktoken is a flutter offline package for a fast BPE tokeniser for OpenAI models.
Dart
8
star
13

fastlane-plugin-apphoster

Ruby
5
star
14

JRBaseKit

Swift
4
star
15

hello_chat_gpt

A program with a command line way to chat with ChatGPT. Use gpt-3.5-turbo Model Api.
Python
4
star
16

Swift5.5_Concurrency_Demo

Swift
4
star
17

JFDemoSource

Some Demo Code Set
Swift
3
star
18

NaviteMixinFlutterDemo

A iOS Native Project mixing Flutter Module Demo
HTML
3
star
19

MessageProtocolDemo

A Message Protocol Demo to Replace iOS Notification Way.
Swift
3
star
20

JerryFans

2
star
21

SwiftyVideoTool

A Swifty API for Video Session Export. Support custom Video Setting and make mix water mark with easy API.
Swift
2
star
22

homebrew-hello_chat_gpt

homebrew store with hello_chat_gpt command line tool
Ruby
1
star