Skip to content

Commit

Permalink
(All) Add popup view type for each use-case
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkeppeler committed Apr 21, 2023
1 parent d8e374a commit a404ed2
Show file tree
Hide file tree
Showing 18 changed files with 1,012 additions and 45 deletions.
11 changes: 4 additions & 7 deletions app/src/main/java/com/mk/sheets/compose/ShowcasePopupScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ package com.mk.sheets.compose
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.mk.sheets.compose.samples.PopupSample

@Composable
internal fun ShowcasePopupScreen() {

var showPopup by rememberSaveable { mutableStateOf(false) }
val popupState = rememberUseCaseState(false)
Column(
Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {

ElevatedButton(
onClick = { showPopup = true }
onClick = { popupState.show() }
) {
Text(text = "Show PopUp")
}
Expand All @@ -50,10 +50,7 @@ internal fun ShowcasePopupScreen() {
textAlign = TextAlign.Center
)

PopupSample(
visible = showPopup,
onHide = { showPopup = false }
)
PopupSample(popupState)
}
}

48 changes: 10 additions & 38 deletions app/src/main/java/com/mk/sheets/compose/samples/PopupSample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,24 @@

package com.mk.sheets.compose.samples

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.maxkeppeler.sheets.calendar.CalendarView
import com.maxkeppeker.sheets.core.models.base.UseCaseState
import com.maxkeppeler.sheets.calendar.CalendarPopup
import com.maxkeppeler.sheets.calendar.models.CalendarConfig
import com.maxkeppeler.sheets.calendar.models.CalendarSelection
import com.maxkeppeler.sheets.calendar.models.CalendarStyle

@Composable
internal fun PopupSample(visible: Boolean, onHide: () -> Unit) {
internal fun PopupSample(state: UseCaseState) {

if (!visible) return

Popup(
CalendarPopup(
state = state,
alignment = Alignment.Center,
onDismissRequest = { onHide() },
) {
Box(
Modifier
.wrapContentWidth()
.widthIn(max = 300.dp)
) {
Surface(
shape = MaterialTheme.shapes.medium,
color = MaterialTheme.colorScheme.surface,
shadowElevation = 4.dp,
) {
CalendarView(
useCaseState = rememberUseCaseState(visible = true,
onCloseRequest = { onHide() },
),
config = CalendarConfig(
style = CalendarStyle.WEEK
),
selection = CalendarSelection.Dates {},
)
}
}
}
config = CalendarConfig(
style = CalendarStyle.WEEK
),
selection = CalendarSelection.Dates {},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2022-2023. Maximilian Keppeler (https://www.maxkeppeler.com)
*
* 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:https://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.
*/
@file:OptIn(ExperimentalMaterial3Api::class)

package com.maxkeppeler.sheets.calendar

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.window.PopupProperties
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.UseCaseState
import com.maxkeppeker.sheets.core.views.base.PopupBase
import com.maxkeppeler.sheets.calendar.models.CalendarConfig
import com.maxkeppeler.sheets.calendar.models.CalendarSelection

/**
* Calendar popup for the use-case to select a date or period in a typical calendar-view.
* @param state The state of the sheet.
* @param selection The selection configuration for the popup.
* @param config The general configuration for the popup.
* @param header The header to be displayed at the top of the popup.
* @param alignment The alignment of the popup.
* @param offset The offset of the popup.
* @param properties PopupProperties for further customization of this popup's behavior.
*/
@ExperimentalMaterial3Api
@Composable
fun CalendarPopup(
state: UseCaseState,
selection: CalendarSelection,
config: CalendarConfig = CalendarConfig(),
header: Header? = null,
alignment: Alignment = Alignment.TopStart,
offset: IntOffset = IntOffset(0, 0),
properties: PopupProperties = PopupProperties(),
) {

PopupBase(
state = state,
properties = properties,
alignment = alignment,
offset = offset
) {
CalendarView(
useCaseState = state,
selection = selection,
config = config,
header = header,
)
}
}
66 changes: 66 additions & 0 deletions clock/src/main/java/com/maxkeppeler/sheets/clock/ClockPopup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2022-2023. Maximilian Keppeler (https://www.maxkeppeler.com)
*
* 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:https://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.
*/
@file:OptIn(ExperimentalMaterial3Api::class)

package com.maxkeppeler.sheets.clock

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.window.PopupProperties
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.UseCaseState
import com.maxkeppeker.sheets.core.views.base.PopupBase
import com.maxkeppeler.sheets.clock.models.ClockConfig
import com.maxkeppeler.sheets.clock.models.ClockSelection

/**
* Clock popup for the use-case to to select a clock time.
* @param state The state of the sheet.
* @param selection The selection configuration for the popup.
* @param config The general configuration for the popup.
* @param header The header to be displayed at the top of the popup.
* @param alignment The alignment of the popup.
* @param offset The offset of the popup.
* @param properties PopupProperties for further customization of this popup's behavior.
*/
@ExperimentalMaterial3Api
@Composable
fun ClockPopup(
state: UseCaseState,
selection: ClockSelection,
config: ClockConfig = ClockConfig(),
header: Header? = null,
alignment: Alignment = Alignment.TopStart,
offset: IntOffset = IntOffset(0, 0),
properties: PopupProperties = PopupProperties(),
) {

PopupBase(
state = state,
properties = properties,
alignment = alignment,
offset = offset
) {
ClockView(
useCaseState = state,
selection = selection,
config = config,
header = header,
)
}
}
64 changes: 64 additions & 0 deletions color/src/main/java/com/maxkeppeler/sheets/color/ColorPopup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2022-2023. Maximilian Keppeler (https://www.maxkeppeler.com)
*
* 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:https://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.
*/
@file:OptIn(ExperimentalMaterial3Api::class)

package com.maxkeppeler.sheets.color

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.window.PopupProperties
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.UseCaseState
import com.maxkeppeker.sheets.core.views.base.PopupBase
import com.maxkeppeler.sheets.color.models.ColorConfig
import com.maxkeppeler.sheets.color.models.ColorSelection

/**
* Core popup that functions as the base of a custom use-case.
* @param state The state of the sheet.
* @param selection The selection configuration for the dialog.
* @param config The configuration of the color use-case.
* @param header The header to be displayed at the top of the dialog.
* @param properties The properties of the popup.
*/
@ExperimentalMaterial3Api
@Composable
fun ColorPopup(
state: UseCaseState,
selection: ColorSelection,
config: ColorConfig,
header: Header? = null,
alignment: Alignment = Alignment.TopStart,
offset: IntOffset = IntOffset(0, 0),
properties: PopupProperties = PopupProperties(),
) {

PopupBase(
state = state,
properties = properties,
alignment = alignment,
offset = offset
) {
ColorView(
useCaseState = state,
selection = selection,
config = config,
header = header,
)
}
}
Loading

0 comments on commit a404ed2

Please sign in to comment.