-
Notifications
You must be signed in to change notification settings - Fork 112
Introduces ScreenOverlay and ModalScreenOverlayDialogFactory #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 3 additions & 4 deletions
7
samples/containers/android/src/main/java/com/squareup/sample/container/SampleContainers.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| package com.squareup.sample.container | ||
|
|
||
| import com.squareup.sample.container.overviewdetail.OverviewDetailContainer | ||
| import com.squareup.sample.container.panel.PanelContainer | ||
| import com.squareup.sample.container.panel.ScrimContainer | ||
| import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
| import com.squareup.sample.container.panel.PanelOverlayDialogFactory | ||
| import com.squareup.workflow1.ui.ViewRegistry | ||
| import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
|
|
||
| @OptIn(WorkflowUiExperimentalApi::class) | ||
| val SampleContainers = ViewRegistry( | ||
| BackButtonViewFactory, OverviewDetailContainer, PanelContainer, ScrimContainer | ||
| BackButtonViewFactory, OverviewDetailContainer, PanelOverlayDialogFactory, ScrimContainer | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
...es/containers/android/src/main/java/com/squareup/sample/container/panel/PanelContainer.kt
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
...rs/android/src/main/java/com/squareup/sample/container/panel/PanelOverlayDialogFactory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.squareup.sample.container.panel | ||
|
|
||
| import android.app.Dialog | ||
| import android.graphics.Rect | ||
| import android.graphics.drawable.ColorDrawable | ||
| import android.util.TypedValue | ||
| import android.view.View | ||
| import com.squareup.sample.container.R | ||
| import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
| import com.squareup.workflow1.ui.container.ModalScreenOverlayDialogFactory | ||
| import com.squareup.workflow1.ui.container.setBounds | ||
|
|
||
| /** | ||
| * Android support for [PanelOverlay]. | ||
| */ | ||
| @OptIn(WorkflowUiExperimentalApi::class) | ||
| internal object PanelOverlayDialogFactory : ModalScreenOverlayDialogFactory<PanelOverlay<*>>( | ||
rjrjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type = PanelOverlay::class | ||
| ) { | ||
| override fun buildDialogWithContentView(contentView: View): Dialog { | ||
| val context = contentView.context | ||
| return Dialog(context, R.style.PanelDialog).also { dialog -> | ||
| dialog.setContentView(contentView) | ||
|
|
||
| // Welcome to Android. Nothing workflow-related here, this is just how one | ||
| // finds the window background color for the theme. I sure hope it's better in Compose. | ||
| val maybeWindowColor = TypedValue() | ||
| context.theme.resolveAttribute(android.R.attr.windowBackground, maybeWindowColor, true) | ||
| if ( | ||
| maybeWindowColor.type in TypedValue.TYPE_FIRST_COLOR_INT..TypedValue.TYPE_LAST_COLOR_INT | ||
| ) { | ||
| dialog.window!!.setBackgroundDrawable(ColorDrawable(maybeWindowColor.data)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun updateBounds( | ||
| dialog: Dialog, | ||
| bounds: Rect | ||
| ) { | ||
| val refinedBounds: Rect = if (!dialog.context.isTablet) { | ||
| // On a phone, fill the bounds entirely. | ||
| bounds | ||
| } else { | ||
| if (bounds.height() > bounds.width()) { | ||
| val margin = bounds.height() - bounds.width() | ||
| val topDelta = margin / 2 | ||
| val bottomDelta = margin - topDelta | ||
| Rect(bounds).apply { | ||
| top = bounds.top + topDelta | ||
| bottom = bounds.bottom - bottomDelta | ||
| } | ||
| } else { | ||
| val margin = bounds.width() - bounds.height() | ||
| val leftDelta = margin / 2 | ||
| val rightDelta = margin - leftDelta | ||
| Rect(bounds).apply { | ||
| left = bounds.left + leftDelta | ||
| right = bounds.right - rightDelta | ||
| } | ||
| } | ||
| } | ||
| dialog.setBounds(refinedBounds) | ||
| } | ||
| } | ||
4 changes: 0 additions & 4 deletions
4
samples/containers/android/src/main/res/values-land/bools.xml
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <bool name="is_portrait">true</bool> | ||
| <bool name="is_tablet">false</bool> | ||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
...ntainers/common/src/main/java/com/squareup/sample/container/panel/PanelContainerScreen.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
samples/containers/common/src/main/java/com/squareup/sample/container/panel/PanelOverlay.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.squareup.sample.container.panel | ||
|
|
||
| import com.squareup.workflow1.ui.Screen | ||
| import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
| import com.squareup.workflow1.ui.container.ScreenOverlay | ||
|
|
||
| @OptIn(WorkflowUiExperimentalApi::class) | ||
| class PanelOverlay<T : Screen>( | ||
| override val content: T | ||
| ) : ScreenOverlay<T> |
14 changes: 0 additions & 14 deletions
14
...ntainers/common/src/main/java/com/squareup/sample/container/panel/ScrimContainerScreen.kt
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
samples/containers/common/src/main/java/com/squareup/sample/container/panel/ScrimScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.squareup.sample.container.panel | ||
|
|
||
| import com.squareup.workflow1.ui.Compatible | ||
| import com.squareup.workflow1.ui.Compatible.Companion.keyFor | ||
| import com.squareup.workflow1.ui.Screen | ||
| import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
|
|
||
| /** | ||
| * Show a scrim over some [content], which is invisible if [dimmed] is false, | ||
| * visible if it is true. | ||
| */ | ||
| @OptIn(WorkflowUiExperimentalApi::class) | ||
| class ScrimScreen<T : Screen>( | ||
| val content: T, | ||
| val dimmed: Boolean | ||
| ) : Screen, Compatible { | ||
| override val compatibilityKey = keyFor(content, "ScrimScreen") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.