Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
feat: create a beagle flex view to others developers use (#1466)
Browse files Browse the repository at this point in the history
* create beagle flex view

* add documentation in beagle flex view

* adjust components

* adjust unit test

* add unit test

* adjust lint

* adjust intenral flex view
  • Loading branch information
uziasferreirazup authored Apr 5, 2021
1 parent f586a22 commit b12b833
Show file tree
Hide file tree
Showing 42 changed files with 599 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ constructor(
val width = if (orientation == RecyclerView.VERTICAL) MATCH_PARENT else WRAP_CONTENT
val layoutParams = ViewGroup.LayoutParams(width, WRAP_CONTENT)
it.layoutParams = layoutParams
it.addServerDrivenComponent(children[position])
it.addView(children[position])
}
return ViewHolder(view)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ data class TabItem(

override fun buildView(rootView: RootView): View {
return viewFactory.makeBeagleFlexView(rootView).also {
it.addServerDrivenComponent(child)
it.addView(child)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ internal class ContentAdapter(

override fun instantiateItem(container: ViewGroup, position: Int): Any {
val view = viewFactory.makeBeagleFlexView(rootView).also {
it.addServerDrivenComponent(children[position].child)
it.addView(children[position].child)
}
container.addView(view)
return view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ data class SimpleForm(
simpleFormViewCreated = viewFactory.makeBeagleFlexView(rootView, style ?: Style())
.apply {
beagleComponent = this@SimpleForm
addChildrenForm(this)
addView(children)
}
return simpleFormViewCreated
}
Expand All @@ -81,12 +81,6 @@ data class SimpleForm(
handleEvent(rootView, view, actions, analyticsValue = "onSubmit")
}

private fun addChildrenForm(beagleFlexView: BeagleFlexView) {
children.forEach { child ->
beagleFlexView.addServerDrivenComponent(child)
}
}

private fun searchErrorInHierarchy(parent: ViewGroup): Boolean {
var result = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class ComposeComponent : WidgetView() {

override fun buildView(rootView: RootView): View {
return viewFactory.makeBeagleFlexView(rootView).apply {
addServerDrivenComponent(build())
addView(build())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import br.com.zup.beagle.android.context.ContextComponent
import br.com.zup.beagle.android.context.ContextData
import br.com.zup.beagle.android.utils.StyleManager
import br.com.zup.beagle.android.view.ViewFactory
import br.com.zup.beagle.android.view.custom.BeagleFlexView
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.android.widget.WidgetView
import br.com.zup.beagle.annotation.RegisterWidget
Expand Down Expand Up @@ -63,13 +62,7 @@ data class Container(

handleOnInit(rootView, view)
return view.apply {
addChildren(this)
}
}

private fun addChildren(beagleFlexView: BeagleFlexView) {
children.forEach { child ->
beagleFlexView.addServerDrivenComponent(child)
addView(children)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal data class ScreenComponent(

addNavigationBarIfNecessary(rootView, navigationBar, container)

container.addServerDrivenComponent(child)
container.addView(child)

screenAnalyticsEvent?.let {
container.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ data class ScrollView(
) {
val viewGroup = viewFactory.makeBeagleFlexView(rootView, styleChild)

children.forEach { component ->
viewGroup.addServerDrivenComponent(component, false)
}
viewGroup.addView(children, false)

scrollView.addView(viewGroup)
if (isHorizontal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ internal class ListAdapter(
private fun generateView(newTemplate: ServerDrivenComponent) =
viewFactory.makeBeagleFlexView(listViewModels.rootView).apply {
setIsAutoGenerateIdEnabled(false)
addServerDrivenComponent(newTemplate, false)
addView(newTemplate, false)
layoutParams = generateLayoutParams()
if (orientation == RecyclerView.VERTICAL) {
setHeightAutoAndDirtyAllViews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ internal class PageViewAdapter(

override fun instantiateItem(container: ViewGroup, position: Int): Any {
val view = viewFactory.makeBeagleFlexView(rootView).also {
it.addServerDrivenComponent(children[position])
it.addView(children[position])
}
container.addView(view)
return view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal class PageViewAdapterTwo(

override fun instantiateItem(container: ViewGroup, position: Int): Any {
val view = viewFactory.makeBeagleFlexView(rootView).also {
it.addServerDrivenComponent(children[position])
it.addView(children[position])
}
container.addView(view)
return view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package br.com.zup.beagle.android.context

import android.view.View
import br.com.zup.beagle.android.view.custom.BeagleFlexView
import br.com.zup.beagle.android.view.custom.InternalBeagleFlexView
import br.com.zup.beagle.android.view.viewmodel.ScreenContextViewModel
import br.com.zup.beagle.core.ServerDrivenComponent

Expand All @@ -33,7 +33,7 @@ internal class ContextComponentHandler {
}

private fun addListenerToHandleContext(viewModel: ScreenContextViewModel, view: View) {
if (view !is BeagleFlexView) {
if (view !is InternalBeagleFlexView) {
view.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewDetachedFromWindow(v: View?) {}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package br.com.zup.beagle.android.utils

import android.view.View
import br.com.zup.beagle.android.view.custom.BeagleFlexView
import br.com.zup.beagle.android.view.custom.InternalBeagleFlexView
import br.com.zup.beagle.android.view.viewmodel.GenerateIdViewModel
import br.com.zup.beagle.android.view.viewmodel.ListViewIdViewModel
import br.com.zup.beagle.android.view.viewmodel.OnInitViewModel
Expand Down Expand Up @@ -49,7 +49,7 @@ internal class GenerateIdManager(
onInitViewModel.markToRerun()
}

fun manageId(component: ServerDrivenComponent, view: BeagleFlexView) {
fun manageId(component: ServerDrivenComponent, view: InternalBeagleFlexView) {
(component as? IdentifierComponent)?.let { identifierComponent ->
if (view.isAutoGenerateIdEnabled()) {
if (identifierComponent.id.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import br.com.zup.beagle.android.components.utils.viewExtensionsViewFactory
import br.com.zup.beagle.android.data.serializer.BeagleSerializer
import br.com.zup.beagle.android.engine.renderer.ActivityRootView
import br.com.zup.beagle.android.engine.renderer.FragmentRootView
import br.com.zup.beagle.android.networking.RequestData
import br.com.zup.beagle.android.view.BeagleFragment
import br.com.zup.beagle.android.view.ScreenRequest
Expand All @@ -33,6 +31,8 @@ import br.com.zup.beagle.android.view.custom.OnServerStateChanged
import br.com.zup.beagle.android.view.custom.OnStateChanged
import br.com.zup.beagle.android.view.mapper.toRequestData
import br.com.zup.beagle.android.view.viewmodel.ScreenContextViewModel
import br.com.zup.beagle.android.widget.ActivityRootView
import br.com.zup.beagle.android.widget.FragmentRootView
import br.com.zup.beagle.android.widget.RootView

internal var beagleSerializerFactory = BeagleSerializer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import br.com.zup.beagle.R
import br.com.zup.beagle.android.action.Action
import br.com.zup.beagle.android.context.Bind
import br.com.zup.beagle.android.context.ContextData
import br.com.zup.beagle.android.engine.renderer.ActivityRootView
import br.com.zup.beagle.android.engine.renderer.FragmentRootView
import br.com.zup.beagle.android.view.ViewFactory
import br.com.zup.beagle.android.widget.ActivityRootView
import br.com.zup.beagle.android.widget.FragmentRootView
import br.com.zup.beagle.android.widget.RootView
import br.com.zup.beagle.core.IdentifierComponent
import br.com.zup.beagle.core.ServerDrivenComponent
Expand Down Expand Up @@ -189,9 +189,9 @@ internal fun ServerDrivenComponent.toView(
generateIdManager.createSingleManagerByRootViewId()
val view = viewFactory.makeBeagleFlexView(rootView).apply {
id = rootView.getParentId()
addServerDrivenComponent(this@toView)
addView(this@toView)
}
view.listenerOnViewDetachedFromWindow = {
view.addListenerOnViewDetachedFromWindow {
generateIdManager.onViewDetachedFromWindow(view)
}
return view
Expand Down
Loading

0 comments on commit b12b833

Please sign in to comment.