Skip to content

Latest commit

 

History

History
106 lines (79 loc) · 3.8 KB

README.md

File metadata and controls

106 lines (79 loc) · 3.8 KB

SwiftyFileBrowser

File browser, file manager UI, browser by list, browser by icon,文件浏览器, 列表样式, 图标样式

CI Status Version License Platform

Screen Shot

Listtype Listtype Listtype

Example

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

Requirements

  • iOS 14.0+
  • Swift 5.0+

Feature

  • show files with list style
  • show files with icon style
  • dynamic switch style
  • reload list with difference algorithm

Installation

Cocoapods

SwiftyFileBrowser is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftyFileBrowser'

Usage

1. implement SFile protocol

class FileObject: SFile {

    convenience init(id: String, type: SFileType = .folder, name: String?, detail: String?) {
        self.init()
        self.identifier = id
        self.fileName = name
        self.detailText = detail
        self.fileType = type
    }
    
    var identifier: String = ""
    
    var filePath: String?
    
    var fileName: String?
    
    var detailText: String?
    
    var fileType: SFileType = .unknow
    
    var state: SFileState = .downloading(progress: 0.4)
    
    var thumbnail: UIImage?
    
    var appIcon: UIImage?
}

2. add SwiftyFileBrowser to view

    let sfbView = SwiftyFileBrowser.init(frame: UIScreen.main.bounds, type: .list)
        sfbView.delegate = self
        let files = [
            FileObject.init(id: "111", type: .folder, name: "name111434534534534523423535436346awefasdfas", detail: "2021/09/11-asdgsfgfadsfadfadfasdfadfadfadfadf"),
            FileObject.init(id: "222", name: "name222", detail: "2021/09/13"),
            FileObject.init(id: "333", name: "name333", detail: "2021/09/14"),
            FileObject.init(id: "444", type: .unknow, name: "name444", detail: "2021/09/14"),
            FileObject.init(id: "555", name: "name555", detail: "2021/09/15"),
            FileObject.init(id: "666", name: "name666", detail: "2021/09/16")
        ]
        sfbView.reloadBrowser(files: files)
        self.view.addSubview(sfbView!)

3. add UIMenum to longPress gestrue

        
        let copyEle = UIAction.init(title: "Copy", image: nil, identifier: UIAction.Identifier.init("LongPress-Copy"), discoverabilityTitle: nil, attributes: [], state: .off) { act in
            print("LongPress copy event!,index: \(self.sfbView?.longPressIndex)")
            // TODO: copy logic
        }
        
        let moveEle = UIAction.init(title: "Move", image: nil, identifier: UIAction.Identifier.init("LongPress-Move"), discoverabilityTitle: nil, attributes: [], state: .off) { act in
            print("LongPress Move event!,index: \(self.sfbView?.longPressIndex)")
            // TODO: Move logic
        }
        
        self.sfbView?.longPressMenuElements = [copyEle, moveEle]

Author

Hansen, [email protected]

License

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