forked from facebook/litho
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port 'bordereffects' to 'sample-kotlin' (facebook#380)
Summary: * Like previous PRs this one is porting 'bordereffects' to 'sample-kotlin' as well. Closes facebook#380 Reviewed By: passy Differential Revision: D8355340 Pulled By: marco-cova fbshipit-source-id: a3550e2c1ff3a0c42c41158cb205dd0e10c86dac
- Loading branch information
1 parent
158ee0c
commit a1547ed
Showing
16 changed files
with
626 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sample-kotlin/src/main/java/com/fblitho/lithoktsample/bordereffects/AllBorderSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import com.facebook.litho.Border | ||
import com.facebook.litho.Component | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.Row | ||
import com.facebook.litho.annotations.LayoutSpec | ||
import com.facebook.litho.annotations.OnCreateLayout | ||
import com.facebook.litho.widget.Text | ||
import com.facebook.yoga.YogaEdge | ||
|
||
@LayoutSpec | ||
object AllBorderSpec { | ||
|
||
@OnCreateLayout | ||
fun onCreateLayout(c: ComponentContext): Component = | ||
Row.create(c) | ||
.child( | ||
Text.create(c) | ||
.textSizeSp(20f) | ||
.text("This component has all borders specified to the same color + width")) | ||
.border( | ||
Border.create(c).color(YogaEdge.ALL, NiceColor.BLUE).widthDip(YogaEdge.ALL, 5) | ||
.build()) | ||
.build() | ||
} |
44 changes: 44 additions & 0 deletions
44
...-kotlin/src/main/java/com/fblitho/lithoktsample/bordereffects/AlternateColorBorderSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import com.facebook.litho.Border | ||
import com.facebook.litho.Component | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.Row | ||
import com.facebook.litho.annotations.LayoutSpec | ||
import com.facebook.litho.annotations.OnCreateLayout | ||
import com.facebook.litho.widget.Text | ||
import com.facebook.yoga.YogaEdge | ||
|
||
@LayoutSpec | ||
object AlternateColorBorderSpec { | ||
|
||
@OnCreateLayout | ||
fun onCreateLayout(c: ComponentContext): Component = | ||
Row.create(c) | ||
.child( | ||
Text.create(c) | ||
.textSizeSp(20f) | ||
.text( | ||
"This component has all borders specified to the same width, but not colors")) | ||
.border( | ||
Border.create(c) | ||
.color(YogaEdge.LEFT, NiceColor.RED) | ||
.color(YogaEdge.TOP, NiceColor.YELLOW) | ||
.color(YogaEdge.RIGHT, NiceColor.GREEN) | ||
.color(YogaEdge.BOTTOM, NiceColor.BLUE) | ||
.widthDip(YogaEdge.ALL, 5) | ||
.build()) | ||
.build() | ||
} |
45 changes: 45 additions & 0 deletions
45
.../java/com/fblitho/lithoktsample/bordereffects/AlternateColorCornerPathEffectBorderSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import com.facebook.litho.Border | ||
import com.facebook.litho.Component | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.Row | ||
import com.facebook.litho.annotations.LayoutSpec | ||
import com.facebook.litho.annotations.OnCreateLayout | ||
import com.facebook.litho.widget.Text | ||
import com.facebook.yoga.YogaEdge | ||
|
||
@LayoutSpec | ||
object AlternateColorCornerPathEffectBorderSpec { | ||
|
||
@OnCreateLayout | ||
fun onCreateLayout(c: ComponentContext): Component = | ||
Row.create(c) | ||
.child( | ||
Text.create(c) | ||
.textSizeSp(20f) | ||
.text("This component has a path effect with rounded corners + multiple colors")) | ||
.border( | ||
Border.create(c) | ||
.widthDip(YogaEdge.ALL, 20) | ||
.color(YogaEdge.LEFT, NiceColor.RED) | ||
.color(YogaEdge.TOP, NiceColor.ORANGE) | ||
.color(YogaEdge.RIGHT, NiceColor.GREEN) | ||
.color(YogaEdge.BOTTOM, NiceColor.BLUE) | ||
.radiusDip(20f) | ||
.build()) | ||
.build() | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...c/main/java/com/fblitho/lithoktsample/bordereffects/AlternateColorPathEffectBorderSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import com.facebook.litho.Border | ||
import com.facebook.litho.Component | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.Row | ||
import com.facebook.litho.annotations.LayoutSpec | ||
import com.facebook.litho.annotations.OnCreateLayout | ||
import com.facebook.litho.widget.Text | ||
import com.facebook.yoga.YogaEdge | ||
|
||
@LayoutSpec | ||
object AlternateColorPathEffectBorderSpec { | ||
|
||
@OnCreateLayout | ||
fun onCreateLayout(c: ComponentContext): Component = | ||
Row.create(c) | ||
.child( | ||
Text.create(c) | ||
.textSizeSp(20f) | ||
.text("This component has a path effect with multiple colors")) | ||
.border( | ||
Border.create(c) | ||
.color(YogaEdge.LEFT, NiceColor.RED) | ||
.color(YogaEdge.TOP, NiceColor.ORANGE) | ||
.color(YogaEdge.RIGHT, NiceColor.GREEN) | ||
.color(YogaEdge.BOTTOM, NiceColor.BLUE) | ||
.widthDip(YogaEdge.ALL, 5) | ||
.discreteEffect(5f, 10f) | ||
.build()) | ||
.build() | ||
} |
46 changes: 46 additions & 0 deletions
46
...in/src/main/java/com/fblitho/lithoktsample/bordereffects/AlternateColorWidthBorderSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import com.facebook.litho.Border | ||
import com.facebook.litho.Component | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.Row | ||
import com.facebook.litho.annotations.LayoutSpec | ||
import com.facebook.litho.annotations.OnCreateLayout | ||
import com.facebook.litho.widget.Text | ||
import com.facebook.yoga.YogaEdge | ||
|
||
@LayoutSpec | ||
object AlternateColorWidthBorderSpec { | ||
|
||
@OnCreateLayout | ||
fun onCreateLayout(c: ComponentContext): Component = | ||
Row.create(c) | ||
.child( | ||
Text.create(c) | ||
.textSizeSp(20f) | ||
.text("This component has each border specified to a different color + width")) | ||
.border( | ||
Border.create(c) | ||
.color(YogaEdge.LEFT, NiceColor.RED) | ||
.color(YogaEdge.TOP, NiceColor.YELLOW) | ||
.color(YogaEdge.RIGHT, NiceColor.GREEN) | ||
.color(YogaEdge.BOTTOM, NiceColor.BLUE) | ||
.widthDip(YogaEdge.LEFT, 2) | ||
.widthDip(YogaEdge.TOP, 4) | ||
.widthDip(YogaEdge.RIGHT, 8) | ||
.widthDip(YogaEdge.BOTTOM, 16) | ||
.build()) | ||
.build() | ||
} |
45 changes: 45 additions & 0 deletions
45
...-kotlin/src/main/java/com/fblitho/lithoktsample/bordereffects/AlternateWidthBorderSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import com.facebook.litho.Border | ||
import com.facebook.litho.Component | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.Row | ||
import com.facebook.litho.annotations.LayoutSpec | ||
import com.facebook.litho.annotations.OnCreateLayout | ||
import com.facebook.litho.widget.Text | ||
import com.facebook.yoga.YogaEdge | ||
|
||
@LayoutSpec | ||
object AlternateWidthBorderSpec { | ||
|
||
@OnCreateLayout | ||
fun onCreateLayout(c: ComponentContext): Component = | ||
Row.create(c) | ||
.child( | ||
Text.create(c) | ||
.textSizeSp(20f) | ||
.text( | ||
"This component has all borders specified to the same color, but not width")) | ||
.border( | ||
Border.create(c) | ||
.color(YogaEdge.ALL, NiceColor.MAGENTA) | ||
.widthDip(YogaEdge.LEFT, 2) | ||
.widthDip(YogaEdge.TOP, 4) | ||
.widthDip(YogaEdge.RIGHT, 8) | ||
.widthDip(YogaEdge.BOTTOM, 16) | ||
.build()) | ||
.build() | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
sample-kotlin/src/main/java/com/fblitho/lithoktsample/bordereffects/BorderEffectsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import android.os.Bundle | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.LithoView | ||
import com.fblitho.lithoktsample.NavigatableDemoActivity | ||
|
||
class BorderEffectsActivity : NavigatableDemoActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView( | ||
LithoView.create(this, BorderEffectsComponent.create(ComponentContext(this)).build())) | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...otlin/src/main/java/com/fblitho/lithoktsample/bordereffects/BorderEffectsComponentSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* This file provided by Facebook is for non-commercial testing and evaluation | ||
* purposes only. Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.fblitho.lithoktsample.bordereffects | ||
|
||
import com.facebook.litho.Component | ||
import com.facebook.litho.ComponentContext | ||
import com.facebook.litho.annotations.FromEvent | ||
import com.facebook.litho.annotations.LayoutSpec | ||
import com.facebook.litho.annotations.OnCreateLayout | ||
import com.facebook.litho.annotations.OnEvent | ||
import com.facebook.litho.sections.SectionContext | ||
import com.facebook.litho.sections.common.DataDiffSection | ||
import com.facebook.litho.sections.common.RenderEvent | ||
import com.facebook.litho.sections.widget.RecyclerCollectionComponent | ||
import com.facebook.litho.widget.ComponentRenderInfo | ||
import com.facebook.litho.widget.RenderInfo | ||
import com.facebook.litho.widget.Text | ||
import java.lang.reflect.InvocationTargetException | ||
|
||
@LayoutSpec | ||
object BorderEffectsComponentSpec { | ||
|
||
private val componentsToBuild = listOf( | ||
AlternateColorBorder::class.java, | ||
AlternateWidthBorder::class.java, | ||
AlternateColorWidthBorder::class.java, | ||
RtlColorWidthBorder::class.java, | ||
DashPathEffectBorder::class.java, | ||
VerticalDashPathEffectBorder::class.java, | ||
AlternateColorPathEffectBorder::class.java, | ||
AlternateColorCornerPathEffectBorder::class.java, | ||
CompositePathEffectBorder::class.java, | ||
VaryingRadiiBorder::class.java) | ||
|
||
@OnCreateLayout | ||
fun onCreateLayout(c: ComponentContext): Component = | ||
RecyclerCollectionComponent.create(c) | ||
.disablePTR(true) | ||
.section( | ||
DataDiffSection.create<Class<out Component>>(SectionContext(c)) | ||
.data(componentsToBuild) | ||
.renderEventHandler(BorderEffectsComponent.onRender(c)) | ||
.build()) | ||
.build() | ||
|
||
@OnEvent(RenderEvent::class) | ||
fun onRender(c: ComponentContext, @FromEvent model: Class<out Component>): RenderInfo { | ||
val component = try { | ||
val createMethod = model.getMethod("create", ComponentContext::class.java) | ||
val componentBuilder = createMethod.invoke(null, c) as Component.Builder<*> | ||
componentBuilder.build() | ||
} catch (ex: Exception) { | ||
val textComponent = Text.create(c).textSizeDip(32f).text(ex.localizedMessage).build() | ||
|
||
when (ex) { | ||
is NoSuchMethodException, | ||
is IllegalAccessException, | ||
is IllegalArgumentException, | ||
is InvocationTargetException -> textComponent | ||
else -> textComponent | ||
} | ||
} | ||
|
||
return ComponentRenderInfo.create() | ||
.component(component) | ||
.build() | ||
} | ||
} |
Oops, something went wrong.