diff --git a/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/inset/InsetTextView.kt b/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/inset/InsetTextView.kt new file mode 100644 index 00000000..c696840e --- /dev/null +++ b/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/inset/InsetTextView.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.components.compose.molecule.inset + +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextAlign +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.typography +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_8 + +@Composable +fun InsetTextView( + text: String, + modifier: Modifier = Modifier +) { + InsetView( + modifier = modifier, + childView = { + Text( + modifier = Modifier.padding(vertical = hmrc_spacing_8), + text = text, + style = typography.body, + textAlign = TextAlign.Start, + ) + } + ) +} diff --git a/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/inset/InsetView.kt b/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/inset/InsetView.kt new file mode 100644 index 00000000..97f8269a --- /dev/null +++ b/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/inset/InsetView.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.components.compose.molecule.inset + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.IntrinsicSize +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.material3.Divider +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.RectangleShape +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_16 +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_4 + +@Composable +fun InsetView( + modifier: Modifier = Modifier, + childView: @Composable () -> Unit, +) { + Column { + Row(modifier = modifier.height(IntrinsicSize.Min)) { + Divider( + color = colors.hmrcGrey2, + modifier = Modifier + .fillMaxHeight() + .clip(RectangleShape) + .padding(end = hmrc_spacing_16) + .width(hmrc_spacing_4) + ) + childView() + } + } +} diff --git a/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/titleBodyView/TitleBodyView.kt b/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/titleBodyView/TitleBodyView.kt deleted file mode 100644 index c7d28dbf..00000000 --- a/components-compose/src/main/java/uk/gov/hmrc/components/compose/molecule/titleBodyView/TitleBodyView.kt +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2021 HM Revenue & Customs - * - * 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 uk.gov.hmrc.components.compose.molecule.titleBodyView - -class TitleBodyView diff --git a/components-compose/src/main/java/uk/gov/hmrc/components/compose/ui/theme/Dimens.kt b/components-compose/src/main/java/uk/gov/hmrc/components/compose/ui/theme/Dimens.kt index d3eeb99c..40041a21 100644 --- a/components-compose/src/main/java/uk/gov/hmrc/components/compose/ui/theme/Dimens.kt +++ b/components-compose/src/main/java/uk/gov/hmrc/components/compose/ui/theme/Dimens.kt @@ -17,6 +17,7 @@ package uk.gov.hmrc.components.compose.ui.theme import androidx.compose.ui.unit.dp +val hmrc_spacing_4 = 4.dp val hmrc_spacing_8 = 8.dp val hmrc_spacing_16 = 16.dp val hmrc_icon_size_24 = 24.dp diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/model/AtomItem.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/model/ComponentMenuItem.kt similarity index 89% rename from sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/model/AtomItem.kt rename to sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/model/ComponentMenuItem.kt index 075a1f5b..9c9cd3e0 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/model/AtomItem.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/model/ComponentMenuItem.kt @@ -18,4 +18,4 @@ package uk.gov.hmrc.sample_compose_fragments.data.model import androidx.annotation.StringRes import uk.gov.hmrc.sample_compose_fragments.presentation.screens.ComponentItem -class AtomItem(val id: Int, @StringRes override val titleRes: Int): ComponentItem \ No newline at end of file +class ComponentMenuItem(val id: Int, @StringRes override val titleRes: Int): ComponentItem \ No newline at end of file diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/repository/RepositoryImp.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/repository/RepositoryImp.kt index 991c4730..daf31d67 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/repository/RepositoryImp.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/data/repository/RepositoryImp.kt @@ -16,7 +16,7 @@ package uk.gov.hmrc.sample_compose_fragments.data.repository import uk.gov.hmrc.sample_compose_components.R -import uk.gov.hmrc.sample_compose_fragments.data.model.AtomItem +import uk.gov.hmrc.sample_compose_fragments.data.model.ComponentMenuItem import uk.gov.hmrc.sample_compose_fragments.data.model.ColorItem import uk.gov.hmrc.sample_compose_fragments.domain.repository.Repository import javax.inject.Inject @@ -25,8 +25,21 @@ class RepositoryImpl @Inject constructor() : Repository { override suspend fun getColorList() = ColorItem.values().asList() override suspend fun getAtomList() = arrayListOf( - AtomItem(1, R.string.atoms_text), - AtomItem(2, R.string.atoms_buttons), - AtomItem(3, R.string.atoms_divider) + ComponentMenuItem(ATOM_TEXT, R.string.atoms_text), + ComponentMenuItem(ATOM_BUTTON, R.string.atoms_buttons), + ComponentMenuItem(ATOM_DIVIDER, R.string.atoms_divider) ) + override suspend fun getMoleculesList() = arrayListOf( + ComponentMenuItem(MOLECULE_INSET_VIEW, R.string.molecules_inset), + ComponentMenuItem(MOLECULE_INSET_TEXT_VIEW, R.string.molecules_inset_text) + ) + + companion object { + const val ATOM_TEXT = 1 + const val ATOM_BUTTON = 2 + const val ATOM_DIVIDER = 3 + + const val MOLECULE_INSET_VIEW = 1 + const val MOLECULE_INSET_TEXT_VIEW = 2 + } } \ No newline at end of file diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/domain/repository/Repository.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/domain/repository/Repository.kt index 9d77de89..c80dd52b 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/domain/repository/Repository.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/domain/repository/Repository.kt @@ -16,9 +16,10 @@ package uk.gov.hmrc.sample_compose_fragments.domain.repository import uk.gov.hmrc.sample_compose_fragments.data.model.ColorItem -import uk.gov.hmrc.sample_compose_fragments.data.model.AtomItem +import uk.gov.hmrc.sample_compose_fragments.data.model.ComponentMenuItem interface Repository { suspend fun getColorList(): List - suspend fun getAtomList(): List + suspend fun getAtomList(): List + suspend fun getMoleculesList(): List } \ No newline at end of file diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/extension/ModifierExtension.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/extension/ModifierExtension.kt new file mode 100644 index 00000000..268f8915 --- /dev/null +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/extension/ModifierExtension.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.sample_compose_fragments.presentation.extension + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.composed +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.ImageShader +import androidx.compose.ui.graphics.ShaderBrush +import androidx.compose.ui.graphics.TileMode +import androidx.compose.ui.res.imageResource +import uk.gov.hmrc.sample_compose_components.R + +internal fun Modifier.addPlaceholderModifier(): Modifier = composed { + val image = ImageBitmap.imageResource(id = R.drawable.checked_tile) + val repeatImage = remember(image) { + ShaderBrush(ImageShader(image, TileMode.Repeated, TileMode.Repeated)) + } + this.then( + wrapContentHeight() + .fillMaxWidth() + .background(repeatImage) + ) +} diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/atoms/AtomsFragment.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/atoms/AtomsFragment.kt index 84c7a83b..e6523ef4 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/atoms/AtomsFragment.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/atoms/AtomsFragment.kt @@ -31,6 +31,8 @@ import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors import uk.gov.hmrc.sample_compose_components.R import uk.gov.hmrc.sample_compose_components.databinding.FragmentAtomsBinding +import uk.gov.hmrc.sample_compose_fragments.data.repository.RepositoryImpl.Companion.ATOM_BUTTON +import uk.gov.hmrc.sample_compose_fragments.data.repository.RepositoryImpl.Companion.ATOM_TEXT import uk.gov.hmrc.sample_compose_fragments.presentation.screens.ComponentListScreen import uk.gov.hmrc.sample_compose_fragments.presentation.viewModel.AtomsViewModel @@ -52,8 +54,8 @@ class AtomsFragment : Fragment(R.layout.fragment_atoms) { ) { ComponentListScreen(items = listItems, navigateTo = { when (it.id) { - 1 -> findNavController().navigate(R.id.action_atomsFragment_to_textFragment) - 2 -> findNavController().navigate(R.id.action_atomsFragment_to_buttonFragment) + ATOM_TEXT -> findNavController().navigate(R.id.action_atomsFragment_to_textFragment) + ATOM_BUTTON -> findNavController().navigate(R.id.action_atomsFragment_to_buttonFragment) } }) } diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/InsetTextViewFragment.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/InsetTextViewFragment.kt new file mode 100644 index 00000000..755f9635 --- /dev/null +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/InsetTextViewFragment.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.sample_compose_fragments.presentation.fragment.molecules + +import android.os.Bundle +import android.view.View +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.Surface +import androidx.compose.ui.Modifier +import androidx.fragment.app.Fragment +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors +import uk.gov.hmrc.sample_compose_components.R +import uk.gov.hmrc.sample_compose_components.databinding.FragmentComposeExampleBinding +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.InsetTextViewScreen + +class InsetTextViewFragment : Fragment(R.layout.fragment_compose_example) { + + private lateinit var binding: FragmentComposeExampleBinding + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + binding = FragmentComposeExampleBinding.bind(view) + binding.composeView.setContent { + HmrcTheme() { + Surface( + modifier = Modifier.fillMaxHeight().fillMaxWidth(), + color = colors.hmrcPageBackground + ) { + InsetTextViewScreen() + } + } + } + } +} diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/InsetViewFragment.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/InsetViewFragment.kt new file mode 100644 index 00000000..84153f1b --- /dev/null +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/InsetViewFragment.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.sample_compose_fragments.presentation.fragment.molecules + +import android.os.Bundle +import android.view.View +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.Surface +import androidx.compose.ui.Modifier +import androidx.fragment.app.Fragment +import dagger.hilt.android.AndroidEntryPoint +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors +import uk.gov.hmrc.sample_compose_components.R +import uk.gov.hmrc.sample_compose_components.databinding.FragmentComposeExampleBinding +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.InsetViewScreen + +@AndroidEntryPoint +class InsetViewFragment : Fragment(R.layout.fragment_compose_example) { + + private lateinit var binding: FragmentComposeExampleBinding + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + binding = FragmentComposeExampleBinding.bind(view) + binding.composeView.setContent { + HmrcTheme() { + Surface( + modifier = Modifier.fillMaxHeight().fillMaxWidth(), + color = colors.hmrcPageBackground + ) { + InsetViewScreen() + } + } + } + } +} diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/MoleculesFragment.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/MoleculesFragment.kt index 58387803..bf2b610e 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/MoleculesFragment.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/fragment/molecules/MoleculesFragment.kt @@ -17,16 +17,55 @@ package uk.gov.hmrc.sample_compose_fragments.presentation.fragment.molecules import android.os.Bundle import android.view.View +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material3.Surface +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels +import androidx.navigation.fragment.findNavController +import dagger.hilt.android.AndroidEntryPoint +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors import uk.gov.hmrc.sample_compose_components.R import uk.gov.hmrc.sample_compose_components.databinding.FragmentMoleculesBinding +import uk.gov.hmrc.sample_compose_fragments.data.repository.RepositoryImpl.Companion.MOLECULE_INSET_TEXT_VIEW +import uk.gov.hmrc.sample_compose_fragments.data.repository.RepositoryImpl.Companion.MOLECULE_INSET_VIEW +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.ComponentListScreen +import uk.gov.hmrc.sample_compose_fragments.presentation.viewModel.MoleculesViewModel +@AndroidEntryPoint class MoleculesFragment : Fragment(R.layout.fragment_molecules) { private lateinit var binding: FragmentMoleculesBinding + private val viewModel: MoleculesViewModel by activityViewModels() override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding = FragmentMoleculesBinding.bind(view) + + binding.composeViewMolecules.setContent { + val listItems by viewModel.moleculesItems.collectAsState() + HmrcTheme { + Surface( + modifier = Modifier.fillMaxHeight().fillMaxWidth(), + color = colors.hmrcPageBackground + ) { + ComponentListScreen(items = listItems, navigateTo = { + when (it.id) { + MOLECULE_INSET_VIEW -> { + findNavController().navigate(R.id.action_moleculesFragment_to_insetViewFragment) + } + MOLECULE_INSET_TEXT_VIEW -> { + findNavController().navigate(R.id.action_moleculesFragment_to_insetTextViewFragment) + } + } + }) + } + } + } + viewModel.getMoleculesData() } } \ No newline at end of file diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/ButtonScreen.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/ButtonScreen.kt index 86c27786..cf29e72d 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/ButtonScreen.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/ButtonScreen.kt @@ -15,13 +15,8 @@ */ package uk.gov.hmrc.sample_compose_fragments.presentation.screens -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -30,19 +25,20 @@ import uk.gov.hmrc.components.compose.atom.button.PrimaryButton import uk.gov.hmrc.components.compose.atom.button.SecondaryButton import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_16 import uk.gov.hmrc.sample_compose_components.R +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.ScreenScrollViewColumn @Composable fun ButtonScreen() { - Column( - modifier = Modifier.fillMaxWidth().padding(hmrc_spacing_16).verticalScroll(rememberScrollState()) - ) { + ScreenScrollViewColumn { PrimaryButton(text = stringResource(id = R.string.button_primary_example)) {} Spacer(modifier = Modifier.height(hmrc_spacing_16)) PrimaryButton(text = stringResource(id = R.string.button_primary_example_disabled), enabled = false) {} Spacer(modifier = Modifier.height(hmrc_spacing_16)) SecondaryButton(text = stringResource(id = R.string.button_secondary_example), onClick = {}) Spacer(modifier = Modifier.height(hmrc_spacing_16)) - IconButton(text = stringResource(id = R.string.button_icon_example), iconResId = R.drawable.ic_info, onClick = {}) + IconButton(text = stringResource(id = R.string.button_icon_example), + iconResId = R.drawable.ic_info, + onClick = {}) } } \ No newline at end of file diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/InsetTextViewScreen.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/InsetTextViewScreen.kt new file mode 100644 index 00000000..c3569776 --- /dev/null +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/InsetTextViewScreen.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.sample_compose_fragments.presentation.screens + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import uk.gov.hmrc.components.compose.molecule.inset.InsetTextView +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_16 +import uk.gov.hmrc.sample_compose_components.R +import uk.gov.hmrc.sample_compose_fragments.presentation.extension.addPlaceholderModifier +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.PlaceholderHeading +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.ExamplesHeading +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.ScreenScrollViewColumn + +@Composable +fun InsetTextViewScreen() { + ScreenScrollViewColumn { + PlaceholderHeading() + + InsetTextView( + text = stringResource(id = R.string.inset_text_placeholder_text), + modifier = Modifier + .padding(bottom = hmrc_spacing_16) + .addPlaceholderModifier()) + + ExamplesHeading() + + Card( + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(0), + colors = CardDefaults.cardColors(containerColor = HmrcTheme.colors.hmrcWhiteBackground)) { + InsetTextView( + text = stringResource(id = R.string.inset_text_example_text), + modifier = Modifier.padding(hmrc_spacing_16) + ) + } + } +} diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/InsetViewScreen.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/InsetViewScreen.kt new file mode 100644 index 00000000..fc527307 --- /dev/null +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/InsetViewScreen.kt @@ -0,0 +1,115 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.sample_compose_fragments.presentation.screens + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import uk.gov.hmrc.components.compose.atom.heading.Heading5 +import uk.gov.hmrc.components.compose.molecule.inset.InsetView +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.colors +import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.typography +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_16 +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_4 +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_8 +import uk.gov.hmrc.sample_compose_components.R +import uk.gov.hmrc.sample_compose_fragments.presentation.extension.addPlaceholderModifier +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.ExamplesHeading +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.PlaceholderHeading +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.ScreenScrollViewColumn + +@Composable +fun InsetViewScreen() { + ScreenScrollViewColumn { + PlaceholderHeading() + + InsetView(modifier = Modifier + .padding(bottom = hmrc_spacing_16) + .addPlaceholderModifier(), + childView = { + Text( + text = stringResource(R.string.inset_placeholder_text), + style = typography.body, + textAlign = TextAlign.Start + ) + } + ) + + ExamplesHeading() + + Card( + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(0), + colors = CardDefaults.cardColors(containerColor = colors.hmrcWhiteBackground)) { + InsetView(modifier = Modifier.padding(hmrc_spacing_16), + childView = { + Column() { + Row { + Text( + text = stringResource(R.string.inset_example_text_line_1_description), + modifier = Modifier.padding(end = hmrc_spacing_4), + style = typography.body, + textAlign = TextAlign.Start + ) + Text( + text = stringResource(id = R.string.inset_example_text_line_1_value), + style = typography.h6, + textAlign = TextAlign.Start + ) + } + Row(modifier = Modifier.padding(top = hmrc_spacing_8)) { + Text( + text = stringResource(R.string.inset_example_text_line_2_description), + modifier = Modifier.padding(end = hmrc_spacing_4), + style = typography.body, + textAlign = TextAlign.Start + ) + Text( + text = stringResource(id = R.string.inset_example_text_line_2_value), + style = typography.h6, + textAlign = TextAlign.Start + ) + } + Row(modifier = Modifier.padding(top = hmrc_spacing_8)) { + Text( + text = stringResource(R.string.inset_example_text_line_3_description), + modifier = Modifier.padding(end = hmrc_spacing_4), + style = typography.body, + textAlign = TextAlign.Start + ) + Text( + text = stringResource(id = R.string.inset_example_text_line_3_value), + style = typography.h6, + textAlign = TextAlign.Start + ) + } + } + } + ) + } + } +} diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/TextScreen.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/TextScreen.kt index 2ba60d2c..33abb699 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/TextScreen.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/TextScreen.kt @@ -31,18 +31,16 @@ import uk.gov.hmrc.components.compose.atom.heading.Heading5 import uk.gov.hmrc.components.compose.ui.theme.HmrcTheme.typography import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_16 import uk.gov.hmrc.sample_compose_components.R +import uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate.ScreenScrollViewColumn @Composable fun TextScreen() { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(start = hmrc_spacing_16, end = hmrc_spacing_16) - .verticalScroll(rememberScrollState()) - ) { + ScreenScrollViewColumn { Heading3(text = stringResource(id = R.string.text_heading3)) Text( - text = stringResource(id = R.string.text_h3), style = typography.h3, modifier = Modifier.padding(top = hmrc_spacing_16) + text = stringResource(id = R.string.text_h3), + style = typography.h3, + modifier = Modifier.padding(top = hmrc_spacing_16) ) Heading4(text = stringResource(id = R.string.text_heading4), modifier = Modifier.padding(top = hmrc_spacing_16)) Text( @@ -74,7 +72,7 @@ fun TextScreen() { modifier = Modifier.padding(top = hmrc_spacing_16) ) BulletedTextView(text = stringResource(id = R.string.text_bullet_2), - modifier = Modifier.padding(vertical = hmrc_spacing_16) + modifier = Modifier.padding(top = hmrc_spacing_16) ) } } diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/sampletemplate/ComposableTemplate.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/sampletemplate/ComposableTemplate.kt new file mode 100644 index 00000000..64691d5d --- /dev/null +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/screens/sampletemplate/ComposableTemplate.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.sample_compose_fragments.presentation.screens.sampletemplate + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import uk.gov.hmrc.components.compose.atom.heading.Heading5 +import uk.gov.hmrc.components.compose.ui.theme.hmrc_spacing_16 +import uk.gov.hmrc.sample_compose_components.R + +@Composable +fun ScreenScrollViewColumn(content: @Composable ColumnScope.() -> Unit) { + Column( + modifier = Modifier + .fillMaxWidth() + .verticalScroll(rememberScrollState()) + .padding(hmrc_spacing_16) + ) { + content.invoke(this) + } +} + +@Composable +fun PlaceholderHeading() { + Heading5(text = stringResource(id = R.string.heading_placeholder_plural), + modifier = Modifier.padding(bottom = hmrc_spacing_16)) +} + +@Composable +fun ExamplesHeading() { + Heading5(text = stringResource(id = R.string.heading_example_plural), + modifier = Modifier.padding(bottom = hmrc_spacing_16)) +} diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/viewModel/AtomsViewModel.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/viewModel/AtomsViewModel.kt index cb61ec74..219818ae 100644 --- a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/viewModel/AtomsViewModel.kt +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/viewModel/AtomsViewModel.kt @@ -23,15 +23,15 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import uk.gov.hmrc.sample_compose_fragments.data.model.AtomItem +import uk.gov.hmrc.sample_compose_fragments.data.model.ComponentMenuItem import uk.gov.hmrc.sample_compose_fragments.domain.repository.Repository import javax.inject.Inject @HiltViewModel class AtomsViewModel @Inject constructor(private val repository: Repository) : ViewModel() { - private val _atomsItems = MutableStateFlow(listOf()) - val atomsItems: StateFlow> get() = _atomsItems + private val _atomsItems = MutableStateFlow(listOf()) + val atomsItems: StateFlow> get() = _atomsItems fun getAtomsData() { viewModelScope.launch { diff --git a/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/viewModel/MoleculesViewModel.kt b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/viewModel/MoleculesViewModel.kt new file mode 100644 index 00000000..7bc1639a --- /dev/null +++ b/sample-compose-fragments/src/main/java/uk/gov/hmrc/sample_compose_fragments/presentation/viewModel/MoleculesViewModel.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * 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 uk.gov.hmrc.sample_compose_fragments.presentation.viewModel + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import uk.gov.hmrc.sample_compose_fragments.data.model.ComponentMenuItem +import uk.gov.hmrc.sample_compose_fragments.domain.repository.Repository +import javax.inject.Inject + +@HiltViewModel +class MoleculesViewModel @Inject constructor(private val repository: Repository) : ViewModel() { + + private val _moleculesItems = MutableStateFlow(listOf()) + val moleculesItems: StateFlow> get() = _moleculesItems + + fun getMoleculesData() { + viewModelScope.launch { + withContext(Dispatchers.Default) { + _moleculesItems.value = repository.getMoleculesList() + } + } + } +} \ No newline at end of file diff --git a/sample-compose-fragments/src/main/res/drawable-night/checked_tile.png b/sample-compose-fragments/src/main/res/drawable-night/checked_tile.png new file mode 100644 index 00000000..d99f3360 Binary files /dev/null and b/sample-compose-fragments/src/main/res/drawable-night/checked_tile.png differ diff --git a/sample-compose-fragments/src/main/res/drawable/checked_tile.png b/sample-compose-fragments/src/main/res/drawable/checked_tile.png new file mode 100644 index 00000000..99ff5b9c Binary files /dev/null and b/sample-compose-fragments/src/main/res/drawable/checked_tile.png differ diff --git a/sample-compose-fragments/src/main/res/layout/fragment_compose_example.xml b/sample-compose-fragments/src/main/res/layout/fragment_compose_example.xml new file mode 100644 index 00000000..d7c4ad9a --- /dev/null +++ b/sample-compose-fragments/src/main/res/layout/fragment_compose_example.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/sample-compose-fragments/src/main/res/layout/fragment_molecules.xml b/sample-compose-fragments/src/main/res/layout/fragment_molecules.xml index 488f520f..3396947a 100644 --- a/sample-compose-fragments/src/main/res/layout/fragment_molecules.xml +++ b/sample-compose-fragments/src/main/res/layout/fragment_molecules.xml @@ -14,16 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. --> - + android:orientation="vertical" + android:name="uk.gov.hmrc.sample_compose_fragments.presentation.fragment.molecules.MoleculesFragment"> - - + android:layout_height="wrap_content" /> \ No newline at end of file diff --git a/sample-compose-fragments/src/main/res/menu/bottom_bar_menu.xml b/sample-compose-fragments/src/main/res/menu/bottom_bar_menu.xml index 593df4e3..380babab 100644 --- a/sample-compose-fragments/src/main/res/menu/bottom_bar_menu.xml +++ b/sample-compose-fragments/src/main/res/menu/bottom_bar_menu.xml @@ -21,7 +21,7 @@ android:title="@string/title_organisms" /> - - + + + + + + + + + + + + + + + + \ No newline at end of file