• Stars
    star
    294
  • Rank 141,303 (Top 3 %)
  • Language
    Swift
  • License
    Other
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

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

Repository Details

SwipeCell is a SwiftUI library, used to achieve the left and right sliding menu effect similar to the iOS mail app.

SwipeCell

SwipeCell 是一个用Swift 5.3开发的 SwiftUI库.目标是为了实现类似iOS Mail程序实现的左右滑动菜单功能. SwipeCell 需要 XCode 12 ,iOS 14

Demo

配置Button

let button1 = SwipeCellButton(buttonStyle: .titleAndImage,
                title: "Mark", 
                systemImage: "bookmark",
                titleColor: .white, 
                imageColor: .white, 
                view: nil,   
                backgroundColor: .green,
                action: {bookmark.toggle()},
                feedback:true
                )
//你可以将按钮设置成任意View从而实现更复杂的设计以及动态效果
let button3 = SwipeCellButton(buttonStyle: .view, title:"",systemImage: "", view: {
    AnyView(
        Group{
            if unread {
                Image(systemName: "envelope.badge")
                    .foregroundColor(.white)
                    .font(.title)
            }
            else {
                Image(systemName: "envelope.open")
                    .foregroundColor(.white)
                    .font(.title)
            }
        }
    )
}, backgroundColor: .orange, action: {unread.toggle()}, feedback: false)

配置Slot

let slot1 = SwipeCellSlot(slots: [button2,button1])
let slot2 = SwipeCellSlot(slots: [button4], slotStyle: .destructive, buttonWidth: 60) 
let slot3 = SwipeCellSlot(slots: [button2,button1],slotStyle: .destructiveDelay) 

装配

cellView()
    .swipeCell(cellPosition: .left, leftSlot: slot4, rightSlot: nil)

更多的配置选项

cellView()
    .swipeCell(cellPosition: .both, 
                leftSlot: slot1, 
                rightSlot: slot1 ,
                swipeCellStyle: SwipeCellStyle(
                            alignment: .leading,
                            dismissWidth: 20,
                            appearWidth: 20,
                            destructiveWidth: 240, 
                            vibrationForButton: .error, 
                            vibrationForDestructive: .heavy, 
                            autoResetTime: 3)
                            )

滚动列表自动消除

For List

  List{
     ```
  }
  .dismissSwipeCell()
}

For single cell in ScrollView

ScrollView{
    VStack{
        Text("Mail Title")
            .dismissSwipeCellForScrollView() 
        Text("Mail Content")
        ....
    }
    .frame(maxWidth:.infinity,maxHeight: .infinity)
}
.swipeCell(cellPosition: .both, leftSlot: leftSlot, rightSlot: rightSlot,clip: false)

For LazyVStack in ScrollView

ScrollView{
    LazyVStack{
    ForEach(lists,id:\.self){ item in
       Text("Swipe in scrollView:\(item)")
        .frame(height:80)
        .swipeCell(cellPosition: .both, leftSlot:slot, rightSlot: slot)
        .dismissSwipeCellForScrollViewForLazyVStack()
    }
    }
}

Get Cell Status

HStack{
    Text("Cell Status:")
    Text(status.rawValue)
        .foregroundColor(.red)
        //get the cell status from Environment
        .transformEnvironment(\.cellStatus, transform: { cellStatus in
            let temp = cellStatus
            DispatchQueue.main.async {
                self.status = temp
            }
        })
}
.frame(maxWidth:.infinity,alignment: .center)
.frame(height:100)
.swipeCell(cellPosition: .both, leftSlot: slot, rightSlot: slot)
  • dismissSwipeCell 在editmode下支持选择
  • dismissSwipeCellForScrollView 用于ScrollView,通常用于只有一个Cell的场景,比如说Mail中的邮件内容显示.参看Demo中的演示
  • dismissSwipeCellForScrollViewForLazyVStack 用于ScrollView中使用LazyVStack场景.个别时候会打断滑动菜单出现动画.个人觉得如无特别需要还是使用List代替LazyVStack比较好.

由于SwiftUI没有很好的方案能够获取滚动状态,所以采用了 Introspect实现的上述功能.

destructiveDelay 形式的 button,需要在action中添加 dismissDestructiveDelayButton()已保证在alter执行后,Cell复位

当前问题

  • 动画细节仍然不足
  • EditMode模式下仍有不足

欢迎多提宝贵意见!

SwipeCell is available under the MIT license.

More Repositories

1

SwiftUIOverlayContainer

SwiftUI Overlay Container is a view container component for SwiftUI. It is a customizable, efficient and convenient view manager.
Swift
335
star
2

NavigationViewKit

NavigationViewKit is a NavigationView extension library for SwiftUI.
Swift
113
star
3

SheetKit

an extension library for SwiftUI sheets.
Swift
100
star
4

Infinite4Pager

Infinite4Pager is a flexible and powerful SwiftUI component that provides infinite scrolling capabilities in four directions: up, down, left, and right. It's perfect for creating image galleries, card decks, or any other content that requires seamless navigation in multiple directions.
Swift
98
star
5

BlogCodes

【肘子的Swift笔记】博文中的代码汇总
Swift
98
star
6

SwiftDataKit

SwiftDataKit allows SwiftData developers to access Core Data objects corresponding to SwiftData elements.
Swift
92
star
7

PersistentHistoryTrackingKit

A library for managing Core Data's Persistent History Tracking
Swift
82
star
8

IsScrolling

As the name suggests, IsScrolling provides a ViewModifier to get the current scrolling state of a ScrollView or List in SwiftUI. IsScrolling has good backward and forward compatibility since it is fully implemented natively in SwiftUI. 正如名称所示,IsScrolling 提供了一个 ViewModifier ,用来获取 SwiftUI 中 ScrollView 或 List 当前的滚动状态。由于完全采用了 SwiftUI 原生的方式实现此功能,因此 IsScrolling 具备了很好的前后兼容性。
Swift
74
star
9

MovieHunter

Swift
43
star
10

ShareData_Demo_For_CoreDataWithCloudKit

Demo for wwdc21-10015,how to share data by Core Data with CloudKit
Swift
29
star
11

Todo

Swift
23
star
12

PublishThemeForFatbobmanBlog

A publish theme and plugin for fatbobman.com.Plugins:TruncateHtmlDescription.TagCount,,Bilibili Video,RssPropertiesSetting and more...
Swift
22
star
13

ObservableDefaults

A Swift library that integrates UserDefaults with the new SwiftUI Observation framework
Swift
19
star
14

CoreDataEvolution

A library aimed at modernizing Core Data by incorporating the elegance and safety of SwiftData-style concurrency.
Swift
17
star
15

SwiftDataConcurrencyDemo

Swift
17
star
16

DismissConfirmSheet

iOS14 multiSheet solution. Includes dismiss gesture control
Swift
14
star
17

MOCloner

A tiny library that implements deep copy of NSManagedObject
Swift
10
star
18

TextFieldFomatAndValidateDemo

Swift
9
star
19

PersistentHistoryTrackingDemo

Persistent History Tracking Demo
Swift
9
star
20

ListExample

SwiftUI List example
Swift
7
star
21

CommandExample

SwiftUI 2.0 Commands example
Swift
3
star
22

SimpleLogger

A simple logging library for Swift 6, providing easy-to-use logging functionalities with support for different log levels and backends.
Swift
2
star
23

SwiftIODemo

Swift
2
star
24

MySingleSoureOfTruthDemo

Swift
2
star
25

local-search-engine-for-Publish

local-search-engine-for-publish
Swift
2
star
26

fatbobman.github.io

HTML
2
star
27

SingleStoreDemo

Swift
2
star
28

ModelActorX

ModelActorX is a Swift library that provides custom macros ModelActorX and MainModelActorX to enhance and extend the functionality of SwiftData's ModelActor.
Swift
1
star
29

ShareCode

Some code snippets for sharing 一些用于分享的代码片段
Swift
1
star
30

blogComments

1
star
31

AstroRSSIssue

Astro
1
star
32

FatBlog

CSS
1
star
33

CoreDataInPreview

演示如何为SwiftUI的Preview提供Core Data数据
Swift
1
star
34

LocalizationDemoForBlogPost

Swift
1
star
35

CustomParseableFormatStyleDemo

Swift
1
star