Skip to content

Commit 6c15154

Browse files
author
Luc Dion
committed
Add another introduction example
1 parent 6360668 commit 6c15154

File tree

2 files changed

+83
-8
lines changed

2 files changed

+83
-8
lines changed

Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ class RayWenderlichTutorialView: BaseView {
147147
override func layoutSubviews() {
148148
super.layoutSubviews()
149149

150-
// Layout the contentView & rootFlexContainer using PinLayout
150+
// 1) Layout the contentView & rootFlexContainer using PinLayout
151151
contentView.pin.top().bottom().left().right()
152152
rootFlexContainer.pin.top().left().right()
153153

154-
// Then let the flexbox container layout itself and adjust the height
154+
// 2) Let the flexbox container layout itself and adjust the height
155155
rootFlexContainer.flex.layout(mode: .adjustHeight)
156156

157-
// Then adjust the scrollview contentSize
157+
// 3) Adjust the scrollview contentSize
158158
contentView.contentSize = rootFlexContainer.frame.size
159159
}
160160

README.md

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ FlexLayout gently wraps the highly optimized [facebook/yoga](https://github.com/
2323

2424
### Content
2525

26-
* [Introduction example](#intro_usage_example)
26+
* [Introduction examples](#intro_usage_example)
2727
* [FlexLayout principles and philosophy](#introduction)
2828
* [Performance](#performance)
2929
* [Documentation](#documentation)
@@ -63,8 +63,8 @@ FlexLayout gently wraps the highly optimized [facebook/yoga](https://github.com/
6363

6464
<br>
6565

66-
## FlexLayout Introduction example <a name="intro_usage_example"></a>
67-
###### Example:
66+
## FlexLayout Introduction examples <a name="intro_usage_example"></a>
67+
###### Example 1:
6868
This example layout multiples views using column and row flexbox containers.
6969

7070
Two steps to use a flexbox container:
@@ -117,7 +117,82 @@ override func layoutSubviews() {
117117
}
118118
```
119119

120-
:pushpin: This example is available in the [Examples App](#examples_app).
120+
:pushpin: This example is available in the [Examples App](#examples_app). See complete [source code](https://github.com/lucdion/FlexLayout/blob/master/Example/FlexLayoutSample/UI/Examples/Intro/IntroView.swift)
121+
122+
</br>
123+
124+
###### Example 2:
125+
The example implements the [Ray Wenderlich Yoga Tutorial](https://www.raywenderlich.com/161413/yoga-tutorial-using-cross-platform-layout-engine) screen using FlexLayout.
126+
127+
<a href="https://github.com/lucdion/FlexLayout/blob/master/Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialView.swift"><img src="docs/images/examples/flexlayout_exampleapp_ray_wenderlich_tutorial.png" alt="FlexLayout example" width=200/></a>
128+
129+
```swift
130+
init() {
131+
...
132+
133+
rootFlexContainer.flex.define { (flex) in
134+
// Image
135+
flex.addItem(episodeImageView).grow(1).backgroundColor(.gray)
136+
137+
// Summary row
138+
flex.addItem().direction(.row).padding(padding).define({ (flex) in
139+
flex.addItem(summaryPopularityLabel).grow(1)
140+
141+
flex.addItem().direction(.row).justifyContent(.spaceBetween).grow(2).define({ (flex) in
142+
flex.addItem(yearLabel)
143+
flex.addItem(ratingLabel)
144+
flex.addItem(lengthLabel)
145+
})
146+
147+
flex.addItem().width(100).height(1).grow(1)
148+
})
149+
150+
// Title row
151+
flex.addItem().direction(.row).padding(padding).define({ (flex) in
152+
flex.addItem(episodeIdLabel)
153+
flex.addItem(episodeTitleLabel).marginLeft(20)
154+
})
155+
156+
// Description section
157+
flex.addItem().paddingHorizontal(paddingHorizontal).define({ (flex) in
158+
flex.addItem(descriptionLabel)
159+
flex.addItem(castLabel)
160+
flex.addItem(creatorsLabel)
161+
})
162+
163+
// Action row
164+
flex.addItem().direction(.row).padding(padding).define({ (flex) in
165+
flex.addItem(addActionView)
166+
flex.addItem(shareActionView)
167+
})
168+
169+
// Tabs row
170+
flex.addItem().direction(.row).padding(padding).define({ (flex) in
171+
flex.addItem(episodesTabView)
172+
flex.addItem(moreTabView)
173+
})
174+
175+
// Shows TableView
176+
flex.addItem(showsTableView).grow(1)
177+
}
178+
}
179+
180+
override func layoutSubviews() {
181+
super.layoutSubviews()
182+
183+
// 1) Layout the contentView & rootFlexContainer using PinLayout
184+
contentView.pin.top().bottom().left().right()
185+
rootFlexContainer.pin.top().left().right()
186+
187+
// 2) Let the flexbox container layout itself and adjust the height
188+
rootFlexContainer.flex.layout(mode: .adjustHeight)
189+
190+
// 3) Adjust the scrollview contentSize
191+
contentView.contentSize = rootFlexContainer.frame.size
192+
}
193+
```
194+
195+
:pushpin: This example is available in the [Examples App](#examples_app). See complete [source code](https://github.com/lucdion/FlexLayout/blob/master/Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialView.swift)
121196

122197
<br>
123198

@@ -882,7 +957,7 @@ Then, run `pod install`.
882957
There is an Example app that expose some usage example on FlexLayout, including:
883958

884959
* The [example](#intro_usage_example) presented priviously in this README.
885-
* An implementation of the [Ray Wenderlich Yoga Turorial](https://www.raywenderlich.com/161413/yoga-tutorial-using-cross-platform-layout-engine). This example is the most complete one.
960+
* An implementation of the [Ray Wenderlich Yoga Tutorial](https://www.raywenderlich.com/161413/yoga-tutorial-using-cross-platform-layout-engine). This example is the most complete one.
886961
* Implementation of all [Yoga's examples](https://facebook.github.io/yoga/): C, Obj-C, Java, C#, Android
887962

888963
:pushpin: Tap on images to see the example's source code.

0 commit comments

Comments
 (0)