Latest 0.4.1
Homepage https://github.com/leavez/ComponentSwift
License MIT
Platforms ios 8.1
Dependencies ComponentKit, CKTableViewTransactionalDataSource
Authors

ComponentSwift

Platform
Swift
Build Status

ComponentSwift brings ComponentKit to swift.

ComponentKit is a react-inspired native view framework for iOS developed by Facebook. It intruduces a new abstract layer (component) to automatically handle view reuse, meanwhile provide the ability to build smooth list view easily.

ComponentSwift is an objc wrapper of ComponentKit and refined for swift. ComponentSwift is designed to be a subset of ComponentKit, implementing the most commonly used features.

Example

class CellComponent: CompositeComponent {

    init?(text: String) {
        super.init(
            view:
            ViewConfiguration(
                attributes:
                .backgroundColor(.gray),
                .tapGesture(#selector(didTapSelf))
            ),
            component:
            getAnotherComponent(text) //
    }
// ...

or try real demo with pod try ComponentSwift

Supported Features

Support:

  • [x] Component:
    • almost all build-in components.
    • ability to wrap an an existed CKComponent on your own
  • [x] Datasource:
    • CollectionViewTransactionalDatasource
    • TableViewTransactionalDatasource (unofficial)
    • HostingView
  • [x] Response Chain and Actions
  • [x] Scope and State
  • [x] Animation

Not support:

  • [ ] component controller and StatefulViewComponent
  • [ ] things about viewContext, mount
  • [ ] computeLayoutThatFits: overriding
  • [ ] …

Work with legacy code

Legacy CKComponent classes could continue to work in swift when using ComponentSwift. Classes and methods are provided to wrap your legacy components conveniently. Every attributes in ComponentKit have an equivalent in ComponentSwift.

Subclass CSCompositeComponent and use initWithCKComponent in its implementation. Import ComponentSubclass.h to use this stuff. Reference more from WrapExisted in the demo project.

more document here

TLDR

ComponentKit is implemented and used with objc++, which is pretty cool. It’s incompatible with swift, since swift doesn’t support objc++. So comes the ComponentSwift.

A objc wrapper is implemented to bridge componentKit to swift. It create an objc version equivalent for every type in componentKit’s APIs, objc class for c++ struct/class, hiding the c++ header in the implementation. It doesn’t touch deep in componentKit. The runtime code is almost the same to the one using componentKit directly in the simplest situation except for construction of objc layer, so it’s safe to use.

It refined the bridged interface for swift, including notating nullability, adding default parameter and swift-only api. C++’s aggregate initialization is very expressive in componentKit. ComponentSwift try hard to simulate the api with default parameters and ExpressibleByXXXLiteral. At least we got code completion here.

Installation

pod "ComponentSwift"

The lib is released with ComponentKit v0.15.1, whose latest version drop support of cocoapods. For version 0.20, go to branch 0.20.

License

ComponentSwift is available under the MIT license.

Latest podspec

{
    "name": "ComponentSwift",
    "version": "0.4.1",
    "summary": "ComponentSwift brings ComponentKit to swift",
    "description": "ComponentSwift brings ComponentKit to swift.nnComponentKit is a react-inspired native view framework for iOS developed by Facebook. It intruduce a new abstract layer (component) to automatically handle view reuse, meanwhile provide the ability to build smooth list view easily.nnComponentSwift is an objc wrapper of ComponentKit and refined for swift. ComponentSwift is designed to be a subset of ComponentKit, implementing the most commonly used features.",
    "homepage": "https://github.com/leavez/ComponentSwift",
    "license": {
        "type": "MIT"
    },
    "authors": {
        "leavez": "[email protected]"
    },
    "source": {
        "git": "https://github.com/leavez/ComponentSwift.git",
        "tag": "0.4.1"
    },
    "platforms": {
        "ios": "8.1"
    },
    "source_files": "Sources/**/*.{swift,h,m,mm}",
    "private_header_files": "Sources/private/**/*.{h}",
    "module_map": "Sources/SupportFiles/ComponentSwift.modulemap",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0",
        "CLANG_WARN_DOCUMENTATION_COMMENTS": "NO"
    },
    "dependencies": {
        "ComponentKit": [
            "~>0.15.0"
        ],
        "CKTableViewTransactionalDataSource": [
            " ~> 0.1.0"
        ]
    }
}

Pin It on Pinterest

Share This