Skip to content

Commit

Permalink
Add default layout section to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
devxoul committed Oct 13, 2020
1 parent c8872c0 commit bfc6f01
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ASCollectionFlexLayout is a custom collection layout that allows to use Texture

## Usage

### Create a layout
### Creating a layout

```swift
let layout = ASCollectionFlexLayout()
Expand All @@ -17,7 +17,7 @@ let collectionNode = ASCollectionNode(collectionViewLayout: layout)

If you don't specify the `layoutProvider`, it will use a `ASStackLayout` as default.

### Implement ASCollectionFlexLayoutProvider protocol
### Implementing ASCollectionFlexLayoutProvider protocol

There are two kind of layout specs in ASCollectionFlexLayout:

Expand Down Expand Up @@ -65,6 +65,26 @@ extension MyViewController: ASCollectionFlexLayoutProvider {
}
```

### Using the default layout

You can modify the default layout to apply layout without implementing `ASCollectionFlexLayoutProvider` protocol.

```swift
let layout = ASCollectionFlexLayout()
layout.defaultSectionLayout.alignItems = .center
layout.defaultItemLayout.direction = .vertical
layout.defaultItemLayout.alignItems = .stretch
```

Also you can directly refer to the default layout in the `ASCollectionFlexLayoutProvider` protocol implementation.

```swift
func flexLayout(_ layout: ASCollectionFlexLayout, layoutSpecThatFits constrainedSize: ASSizeRange, forSectionAt section: Int, itemElements: [ASLayoutElement]) -> ASLayoutSpec? {
let insets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 20)
return ASInsetLayoutSpec(insets: insets, child: layout.defaultItemLayout)
}
```

## License

ASCollectionFlexLayout is under MIT license. See the [LICENSE](LICENSE) for more info.

0 comments on commit bfc6f01

Please sign in to comment.