diff --git a/sample/core/src/main/kotlin/br/com/zup/beagle/sample/builder/ComponentScreenBuilder.kt b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/builder/ComponentScreenBuilder.kt index babc9f8..43aa774 100644 --- a/sample/core/src/main/kotlin/br/com/zup/beagle/sample/builder/ComponentScreenBuilder.kt +++ b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/builder/ComponentScreenBuilder.kt @@ -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 @@ -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), diff --git a/sample/core/src/main/kotlin/br/com/zup/beagle/sample/builder/NavigationContextScreenBuilder.kt b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/builder/NavigationContextScreenBuilder.kt new file mode 100644 index 0000000..e5d7174 --- /dev/null +++ b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/builder/NavigationContextScreenBuilder.kt @@ -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" + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) +} diff --git a/sample/core/src/main/kotlin/br/com/zup/beagle/sample/constants/PathConstants.kt b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/constants/PathConstants.kt index ddf51b4..11308c8 100644 --- a/sample/core/src/main/kotlin/br/com/zup/beagle/sample/constants/PathConstants.kt +++ b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/constants/PathConstants.kt @@ -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" diff --git a/sample/core/src/main/kotlin/br/com/zup/beagle/sample/widget/ActionExecutor.kt b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/widget/ActionExecutor.kt new file mode 100644 index 0000000..f909406 --- /dev/null +++ b/sample/core/src/main/kotlin/br/com/zup/beagle/sample/widget/ActionExecutor.kt @@ -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, + val actions: List +): Widget() \ No newline at end of file diff --git a/sample/micronaut/src/main/kotlin/br/com/zup/beagle/sample/micronaut/controller/ScreenController.kt b/sample/micronaut/src/main/kotlin/br/com/zup/beagle/sample/micronaut/controller/ScreenController.kt index 371e2bd..a676ce5 100644 --- a/sample/micronaut/src/main/kotlin/br/com/zup/beagle/sample/micronaut/controller/ScreenController.kt +++ b/sample/micronaut/src/main/kotlin/br/com/zup/beagle/sample/micronaut/controller/ScreenController.kt @@ -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 @@ -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 @@ -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, @@ -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() diff --git a/sample/micronaut/src/main/kotlin/br/com/zup/beagle/sample/micronaut/service/SampleNavigationContextService.kt b/sample/micronaut/src/main/kotlin/br/com/zup/beagle/sample/micronaut/service/SampleNavigationContextService.kt new file mode 100644 index 0000000..19cda68 --- /dev/null +++ b/sample/micronaut/src/main/kotlin/br/com/zup/beagle/sample/micronaut/service/SampleNavigationContextService.kt @@ -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 +} diff --git a/sample/spring/src/main/kotlin/br/com/zup/beagle/sample/spring/controller/ScreenController.kt b/sample/spring/src/main/kotlin/br/com/zup/beagle/sample/spring/controller/ScreenController.kt index 99b6213..dc01e06 100644 --- a/sample/spring/src/main/kotlin/br/com/zup/beagle/sample/spring/controller/ScreenController.kt +++ b/sample/spring/src/main/kotlin/br/com/zup/beagle/sample/spring/controller/ScreenController.kt @@ -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 @@ -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 @@ -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, @@ -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() diff --git a/sample/spring/src/main/kotlin/br/com/zup/beagle/sample/spring/service/SampleNavigationContextService.kt b/sample/spring/src/main/kotlin/br/com/zup/beagle/sample/spring/service/SampleNavigationContextService.kt new file mode 100644 index 0000000..1cd0b20 --- /dev/null +++ b/sample/spring/src/main/kotlin/br/com/zup/beagle/sample/spring/service/SampleNavigationContextService.kt @@ -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 +}