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

feat: Add sample for navigation context #80

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import br.com.zup.beagle.sample.constants.SCREEN_IMAGE_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_LAZY_COMPONENT_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_LIST_VIEW_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NAVIGATION_BAR_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NAVIGATION_CONTEXT_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NETWORK_IMAGE_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_PAGE_VIEW_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_PULL_TO_REFRESH
Expand Down Expand Up @@ -82,6 +83,7 @@ object ComponentScreenBuilder : ScreenBuilder {
createMenu("ScreenBuilder", SCREEN_BUILDER_ENDPOINT),
createMenu("LazyComponent", SCREEN_LAZY_COMPONENT_ENDPOINT),
createMenu("NavigationBar", SCREEN_NAVIGATION_BAR_ENDPOINT),
createMenu("NavigationContext", SCREEN_NAVIGATION_CONTEXT_ENDPOINT),
createMenu("NavigationType", NAVIGATION_TYPE_ENDPOINT),
createMenu("Accessibility Screen", ACCESSIBILITY_SCREEN_ENDPOINT),
createMenu("Compose Component", SCREEN_COMPOSE_COMPONENT_ENDPOINT),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright 2020, 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package br.com.zup.beagle.sample.builder

import br.com.zup.beagle.ext.setFlex
import br.com.zup.beagle.ext.setStyle
import br.com.zup.beagle.sample.widget.ActionExecutor
import br.com.zup.beagle.sample.widget.ActionExecutorType
import br.com.zup.beagle.widget.action.Navigate
import br.com.zup.beagle.widget.action.NavigationContext
import br.com.zup.beagle.widget.action.Route
import br.com.zup.beagle.widget.action.SetContext
import br.com.zup.beagle.widget.context.ContextData
import br.com.zup.beagle.widget.context.expressionOf
import br.com.zup.beagle.widget.core.EdgeValue
import br.com.zup.beagle.widget.core.FlexDirection
import br.com.zup.beagle.widget.core.UnitValue
import br.com.zup.beagle.widget.layout.Container
import br.com.zup.beagle.widget.layout.NavigationBar
import br.com.zup.beagle.widget.layout.Screen
import br.com.zup.beagle.widget.layout.ScreenBuilder
import br.com.zup.beagle.widget.ui.Button
import br.com.zup.beagle.widget.ui.Text

object NavigationContextScreenBuilder : ScreenBuilder {
override fun build() = Screen(
navigationBar = NavigationBar(
title = "Navigation Context",
showBackButton = true
),
child = this.createContent()
)

private fun createContent() = Container(
context = ContextData(id = "text", value = false),
children = listOf(
Text(expressionOf("@{navigationContext.shouldRetry}")),
Button(
text = "Go to next page",
onPress = listOf(
SetContext(contextId = "text", value = true),
Navigate.PushView(
navigationContext = NavigationContext(
value = "Click to go back",
path = "shouldRetry"
),
route = Route.Local(
Screen(
navigationBar = NavigationBar(
title = "Navigation Context",
showBackButton = true
),
child = Container(
children = listOf(
Button(
text = expressionOf("@{navigationContext.shouldRetry}"),
onPress = listOf(
Navigate.PopView(
navigationContext = NavigationContext(
value = ActionExecutorType.NAVIGATE,
path = "shouldRetry"
)
)
)
)
)
)
)
)
)
)
),
createActionExecutor()
)
).setFlex {
flexDirection = FlexDirection.COLUMN
}.setStyle {
margin = EdgeValue(all = UnitValue.real(20.0))
}

private fun createActionExecutor() = ActionExecutor(
trigger = expressionOf("@{navigationContext.shouldRetry}"),
actions = listOf(
Navigate.PushView(
route = Route.Local(
screen = Screen(
navigationBar = NavigationBar(
title = "Navigation Context",
showBackButton = true
),
child = Container(
children = listOf(
Button(
text = "SIGNUP",
onPress = listOf(
Navigate.PopView(
navigationContext = NavigationContext(
value = ActionExecutorType.NAVIGATE,
path = "shouldRetry"
)
)
)
)
)
)
)
)
)
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const val SCREEN_PAGE_VIEW_ENDPOINT = "/page-view-screen"
const val SCREEN_ACTION_ENDPOINT = "/action"
const val SCREEN_LAZY_COMPONENT_ENDPOINT = "/lazy-component"
const val SCREEN_NAVIGATION_BAR_ENDPOINT = "/navigation/bar"
const val SCREEN_NAVIGATION_CONTEXT_ENDPOINT = "/navigation/context"
const val REPRESENTATION_NAVIGATION_BAR_ENDPOINT = "/navigationbar"
const val REPRESENTATION_NAVIGATION_BAR_STYLE_ENDPOINT = "/navigationbar/style"
const val REPRESENTATION_NAVIGATION_BAR_TEXT_ENDPOINT = "/navigationbar/item/text"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2020, 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package br.com.zup.beagle.sample.widget

import br.com.zup.beagle.annotation.RegisterWidget
import br.com.zup.beagle.widget.Widget
import br.com.zup.beagle.widget.action.Action
import br.com.zup.beagle.widget.context.Bind

enum class ActionExecutorType{ NAVIGATE, NOTHING }

@RegisterWidget
class ActionExecutor(
var trigger: Bind<ActionExecutorType>,
val actions: List<Action>
): Widget()
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import br.com.zup.beagle.sample.constants.SCREEN_IMAGE_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_LAZY_COMPONENT_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_LIST_VIEW_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NAVIGATION_BAR_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NAVIGATION_CONTEXT_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NETWORK_IMAGE_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_PAGE_VIEW_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_PULL_TO_REFRESH
Expand Down Expand Up @@ -74,6 +75,7 @@ import br.com.zup.beagle.sample.micronaut.service.SampleImageRemoteService
import br.com.zup.beagle.sample.micronaut.service.SampleLazyComponentService
import br.com.zup.beagle.sample.micronaut.service.SampleListViewService
import br.com.zup.beagle.sample.micronaut.service.SampleNavigationBarService
import br.com.zup.beagle.sample.micronaut.service.SampleNavigationContextService
import br.com.zup.beagle.sample.micronaut.service.SampleNavigationTypeService
import br.com.zup.beagle.sample.micronaut.service.SampleOperationService
import br.com.zup.beagle.sample.micronaut.service.SamplePageViewService
Expand Down Expand Up @@ -107,6 +109,7 @@ class ScreenController(
private val sampleActionService: SampleActionService,
private val sampleLazyComponentService: SampleLazyComponentService,
private val sampleNavigationBarService: SampleNavigationBarService,
private val sampleNavigationContextService: SampleNavigationContextService,
private val sampleNavigationTypeService: SampleNavigationTypeService,
private val sampleComposeComponentService: SampleComposeComponentService,
private val sampleNetworkImageService: SampleImageRemoteService,
Expand Down Expand Up @@ -165,6 +168,9 @@ class ScreenController(
@Get(SCREEN_NAVIGATION_BAR_ENDPOINT)
fun getSampleNavigationBarController() = this.sampleNavigationBarService.createNavigationBarView()

@Get(SCREEN_NAVIGATION_CONTEXT_ENDPOINT)
fun getSampleNavigationContextController() = this.sampleNavigationContextService.createNavigationContextSample()

@Get(REPRESENTATION_NAVIGATION_BAR_ENDPOINT)
fun getSampleNavigationBar() = this.sampleNavigationBarService.navigationBar()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2020, 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package br.com.zup.beagle.sample.micronaut.service

import br.com.zup.beagle.sample.builder.NavigationContextScreenBuilder
import javax.inject.Singleton

@Singleton
class SampleNavigationContextService {
fun createNavigationContextSample() = NavigationContextScreenBuilder
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import br.com.zup.beagle.sample.constants.SCREEN_IMAGE_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_LAZY_COMPONENT_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_LIST_VIEW_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NAVIGATION_BAR_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NAVIGATION_CONTEXT_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_NETWORK_IMAGE_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_PAGE_VIEW_ENDPOINT
import br.com.zup.beagle.sample.constants.SCREEN_PULL_TO_REFRESH
Expand Down Expand Up @@ -74,6 +75,7 @@ import br.com.zup.beagle.sample.spring.service.SampleImageRemoteService
import br.com.zup.beagle.sample.spring.service.SampleLazyComponentService
import br.com.zup.beagle.sample.spring.service.SampleListViewService
import br.com.zup.beagle.sample.spring.service.SampleNavigationBarService
import br.com.zup.beagle.sample.spring.service.SampleNavigationContextService
import br.com.zup.beagle.sample.spring.service.SampleNavigationTypeService
import br.com.zup.beagle.sample.spring.service.SampleOperationService
import br.com.zup.beagle.sample.spring.service.SamplePageViewService
Expand Down Expand Up @@ -105,6 +107,7 @@ class ScreenController(
private val sampleScrollViewService: SampleScrollViewService,
private val samplePageViewService: SamplePageViewService,
private val sampleActionService: SampleActionService,
private val sampleNavigationContextService: SampleNavigationContextService,
private val sampleLazyComponentService: SampleLazyComponentService,
private val sampleNavigationBarService: SampleNavigationBarService,
private val sampleNavigationTypeService: SampleNavigationTypeService,
Expand Down Expand Up @@ -208,6 +211,9 @@ class ScreenController(
@GetMapping(SCREEN_EXAMPLE_ENDPOINT)
fun getNavigationExample() = this.sampleActionService.getNavigateExample()

@GetMapping(SCREEN_NAVIGATION_CONTEXT_ENDPOINT)
fun getSampleNavigationContextController() = this.sampleNavigationContextService.createNavigationContextSample()

@GetMapping(SCREEN_ANALYTICS_ENDPOINT)
fun getAnalyticsExample() = this.sampleAnalyticsService.getAnalyticsExample()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2020, 2022 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package br.com.zup.beagle.sample.spring.service

import br.com.zup.beagle.sample.builder.NavigationContextScreenBuilder
import org.springframework.stereotype.Service

@Service
class SampleNavigationContextService {
fun createNavigationContextSample() = NavigationContextScreenBuilder
}