Skip to content

Commit

Permalink
Port 'bordereffects' to 'sample-kotlin' (facebook#380)
Browse files Browse the repository at this point in the history
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
pavlospt authored and facebook-github-bot committed Jun 14, 2018
1 parent 158ee0c commit a1547ed
Show file tree
Hide file tree
Showing 16 changed files with 626 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sample-kotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="com.fblitho.lithoktsample.LithoApplication"
android:name=".LithoApplication"
android:allowBackup="true"
android:label="Litho Sample"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
Expand All @@ -27,8 +27,9 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.fblitho.lithoktsample.lithography.LithographyActivity"/>
<activity android:name=".lithography.LithographyActivity"/>
<activity android:name=".errors.ErrorHandlingActivity" />
<activity android:name=".bordereffects.BorderEffectsActivity" />
<activity android:name=".animations.animatedbadge.AnimatedBadgeActivity" />
<activity android:name=".animations.animationcomposition.ComposedAnimationsActivity" />
<activity android:name=".animations.expandableelement.ExpandableElementActivity" />
Expand Down
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()
}
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()
}
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()

}
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()
}
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()
}
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()

}
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()))
}
}
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()
}
}
Loading

0 comments on commit a1547ed

Please sign in to comment.