diff --git a/samples/JetNews/HomeCards.cs b/samples/JetNews/HomeCards.cs index 7ea8cd85..0f2e8d28 100644 --- a/samples/JetNews/HomeCards.cs +++ b/samples/JetNews/HomeCards.cs @@ -23,7 +23,7 @@ public static Column BuildHighlight(Post post, .AspectRatio(992f / 296f) .Clip(16), }, - new Spacer(Modifier.Companion.Height(16)), + Spacer.Height(16), new Text(post.Title) { FontSize = 22, @@ -101,7 +101,7 @@ public static Card BuildPopular(Post post, Action onSelectPost) => FontWeight = FontWeight.SemiBold, MaxLines = 2, }, - new Spacer(Modifier.Companion.Weight(1f, fill: true)), + Spacer.Weight(1f), new Text(post.Metadata.Author) { FontSize = 13, diff --git a/samples/JetNews/JetnewsDrawer.cs b/samples/JetNews/JetnewsDrawer.cs index 61b4ea24..65fece61 100644 --- a/samples/JetNews/JetnewsDrawer.cs +++ b/samples/JetNews/JetnewsDrawer.cs @@ -48,7 +48,7 @@ static Row BuildHeader() => { Modifier.Companion.FillMaxWidth().Padding(horizontal: 28, vertical: 24), new Icon(Resource.Drawable.ic_jetnews_logo, "JetNews logo"), - new Spacer(Modifier.Companion.Width(8)), + Spacer.Width(8), new Icon(Resource.Drawable.ic_jetnews_wordmark, "JetNews"), }; diff --git a/samples/JetNews/PostBody.cs b/samples/JetNews/PostBody.cs index a096937c..8c52ec6d 100644 --- a/samples/JetNews/PostBody.cs +++ b/samples/JetNews/PostBody.cs @@ -80,7 +80,7 @@ static Row Quote(Paragraph p) => { Modifier.Companion.Width(4).Height(40).Background(QuoteBar), }, - new Spacer(Modifier.Companion.Width(12)), + Spacer.Width(12), Styled(p, fontSize: 16, fontStyle: FontStyle.Italic), diff --git a/samples/JetNews/PostScreen.cs b/samples/JetNews/PostScreen.cs index 74c0eee0..3b63726a 100644 --- a/samples/JetNews/PostScreen.cs +++ b/samples/JetNews/PostScreen.cs @@ -141,13 +141,13 @@ static Column BuildHero(Post post) => FontSize = 22, FontWeight = FontWeight.SemiBold, }, - new Spacer(Modifier.Companion.Height(4)), + Spacer.Height(4), new Text(post.Subtitle) { FontSize = 14, Color = Color.FromHex("#666666"), }, - new Spacer(Modifier.Companion.Height(8)), + Spacer.Height(8), new Text($"{post.Metadata.Author} · {post.Metadata.Date} · {post.Metadata.ReadTimeMinutes} min read") { FontSize = 12, diff --git a/samples/Jetchat/Conversation.cs b/samples/Jetchat/Conversation.cs index 0fe8f33e..dd50c5f8 100644 --- a/samples/Jetchat/Conversation.cs +++ b/samples/Jetchat/Conversation.cs @@ -183,7 +183,7 @@ static ComposableNode BuildMessages(ConversationUiState ui, ColorScheme scheme, { MessageRow mr => BuildMessageRow(mr.Msg, mr.IsFirstByAuthor, mr.IsLastByAuthor, scheme, popupOpen, onAuthorClicked), HeaderRow hr => BuildDayHeader(hr.Label, scheme), - _ => new Spacer(Modifier.Companion.Width(0)), + _ => Spacer.Width(0), }) { Modifier = Modifier.Companion.FillMaxSize(), @@ -247,7 +247,7 @@ static Row BuildMessageRow(Message m, bool isFirstByAuthor, bool isLastByAuthor, if (isLastByAuthor) row.Add(BuildAvatar(m, scheme, onAuthorClicked)); else - row.Add(new Spacer(Modifier.Companion.Width(74))); + row.Add(Spacer.Width(74)); row.Add(BuildAuthorAndTextMessage(m, isFirstByAuthor, isLastByAuthor, scheme, popupOpen)); return row; @@ -279,7 +279,7 @@ static Column BuildAuthorAndTextMessage(Message m, bool isFirstByAuthor, bool is if (isLastByAuthor) col.Add(BuildAuthorNameTimestamp(m, scheme)); col.Add(BuildChatItemBubble(m, scheme, popupOpen)); - col.Add(new Spacer(Modifier.Companion.Height(isFirstByAuthor ? 8 : 4))); + col.Add(Spacer.Height(isFirstByAuthor ? 8 : 4)); return col; } @@ -293,7 +293,7 @@ static Row BuildAuthorNameTimestamp(Message m, ColorScheme scheme) => Color = scheme.OnSurface, Modifier = Modifier.Companion.Padding(top: 0, bottom: 8, start: 0, end: 0), }, - new Spacer(Modifier.Companion.Width(8)), + Spacer.Width(8), new Text(m.Timestamp) { FontSize = 12, @@ -440,14 +440,14 @@ static ComposableNode BuildSelectorPanel( MutableState selectedSelector) { int sel = selectedSelector.Value; - if (sel == 0) return new Spacer(Modifier.Companion.Width(0)); + if (sel == 0) return Spacer.Width(0); if (sel == SelEmoji) return EmojiSelector.Build(input, scheme); string title = "Functionality currently not available"; string subtitle = "Grab a beverage and check back later!"; return new Column { Modifier.Companion.FillMaxWidth().Height(320).Background(scheme.SurfaceVariant), - new Spacer(Modifier.Companion.Height(96)), + Spacer.Height(96), new Text(title) { FontSize = 16, @@ -455,7 +455,7 @@ static ComposableNode BuildSelectorPanel( Color = scheme.OnSurfaceVariant, Modifier = Modifier.Companion.Padding(horizontal: 16, vertical: 0), }, - new Spacer(Modifier.Companion.Height(8)), + Spacer.Height(8), new Text(subtitle) { FontSize = 14, diff --git a/samples/Jetchat/JetchatDrawer.cs b/samples/Jetchat/JetchatDrawer.cs index 67bd31f4..a26cf12e 100644 --- a/samples/Jetchat/JetchatDrawer.cs +++ b/samples/Jetchat/JetchatDrawer.cs @@ -48,7 +48,7 @@ static Row BuildHeader(ColorScheme scheme) => { Modifier.Companion.FillMaxWidth().Padding(16), JetchatIcon.Build(contentDescription: null, sizeDp: 24), - new Spacer(Modifier.Companion.Width(8)), + Spacer.Width(8), new Text("Jetchat") { FontSize = 18, diff --git a/samples/Jetchat/Profile.cs b/samples/Jetchat/Profile.cs index e6fa0d0f..b6635f0b 100644 --- a/samples/Jetchat/Profile.cs +++ b/samples/Jetchat/Profile.cs @@ -86,7 +86,7 @@ static ComposableNode BuildBody( static ComposableNode BuildProfileHeader(ProfileScreenState state, float containerHeight) { if (state.Photo is null) - return new Spacer(Modifier.Companion.Width(0)); + return Spacer.Width(0); float heroMax = containerHeight / 2f; if (heroMax < 1f) heroMax = 240f; @@ -105,7 +105,7 @@ static Column BuildUserInfoFields(ProfileScreenState state, float containerHeigh { var col = new Column { - new Spacer(Modifier.Companion.Height(8)), + Spacer.Height(8), BuildNameAndPosition(state, scheme), BuildProfileProperty("Display name", state.DisplayName, scheme), BuildProfileProperty("Status", state.Status, scheme), @@ -118,7 +118,7 @@ static Column BuildUserInfoFields(ProfileScreenState state, float containerHeigh // the device, in order to always leave some content at the top. float trailing = containerHeight - 320f; if (trailing < 0f) trailing = 0f; - col.Add(new Spacer(Modifier.Companion.Height((int)trailing))); + col.Add(Spacer.Height((int)trailing)); return col; } diff --git a/samples/Jetchat/RecordButton.cs b/samples/Jetchat/RecordButton.cs index 0437662e..b16f50a2 100644 --- a/samples/Jetchat/RecordButton.cs +++ b/samples/Jetchat/RecordButton.cs @@ -139,7 +139,7 @@ public static ComposableNode BuildRecordingIndicator( Color = scheme.OnSurface, }, - new Spacer(Modifier.Companion.Width(16)), + Spacer.Width(16), new Row { @@ -154,7 +154,7 @@ public static ComposableNode BuildRecordingIndicator( TintArgb = scheme.OnSurfaceVariant, Modifier = Modifier.Companion.Align(Alignment.Vertical.CenterVertically).Size(24), }, - new Spacer(Modifier.Companion.Width(8)), + Spacer.Width(8), new Text("Slide to cancel") { Modifier = Modifier.Companion.Align(Alignment.Vertical.CenterVertically), diff --git a/samples/Reply/EmptyComingSoon.cs b/samples/Reply/EmptyComingSoon.cs index 483c1223..b4b6fbeb 100644 --- a/samples/Reply/EmptyComingSoon.cs +++ b/samples/Reply/EmptyComingSoon.cs @@ -22,7 +22,7 @@ public static ComposableNode Build() => Color = scheme.Primary, Modifier = Modifier.Companion.FillMaxWidth(), }, - new Spacer(Modifier.Companion.Height(8)), + Spacer.Height(8), new Text("This screen is still under construction. This sample will help you learn about adaptive layouts in Jetpack Compose") { FontSize = 14, diff --git a/src/Microsoft.AndroidX.Compose.Gallery/Demos/Navigation/BackHandlerDemo.cs b/src/Microsoft.AndroidX.Compose.Gallery/Demos/Navigation/BackHandlerDemo.cs index fef22cd0..804e6ac4 100644 --- a/src/Microsoft.AndroidX.Compose.Gallery/Demos/Navigation/BackHandlerDemo.cs +++ b/src/Microsoft.AndroidX.Compose.Gallery/Demos/Navigation/BackHandlerDemo.cs @@ -28,20 +28,20 @@ public static class BackHandlerDemo enabled: intercept.Value), new Text("BackHandler is registered while this screen is active."), - new Spacer(Modifier.Companion.Height(12)), + Spacer.Height(12), new Row { new Switch(@checked: intercept.Value, onCheckedChange: v => intercept.Value = v), - new Spacer(Modifier.Companion.Width(12)), + Spacer.Width(12), new Text(intercept.Value ? "Intercepting — system back is consumed" : "Letting back through — pops the gallery screen"), }, - new Spacer(Modifier.Companion.Height(16)), + Spacer.Height(16), new Text($"Back presses intercepted: {pressCount}"), - new Spacer(Modifier.Companion.Height(16)), + Spacer.Height(16), new Text("Try pressing the system back button or swiping from the edge:"), new Text("• With the switch ON the counter ticks and you stay on this screen."), diff --git a/src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt b/src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt index a61d38a1..4cd686dd 100644 --- a/src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt +++ b/src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt @@ -1861,6 +1861,11 @@ static AndroidX.Compose.Sp.operator !=(AndroidX.Compose.Sp left, AndroidX.Compos static AndroidX.Compose.Sp.operator ==(AndroidX.Compose.Sp left, AndroidX.Compose.Sp right) -> bool static AndroidX.Compose.Sp.Pack(AndroidX.Compose.Sp? value) -> long static AndroidX.Compose.Sp.Zero.get -> AndroidX.Compose.Sp +static AndroidX.Compose.Spacer.Height(AndroidX.Compose.Dp dp) -> AndroidX.Compose.Spacer! +static AndroidX.Compose.Spacer.Size(AndroidX.Compose.Dp dp) -> AndroidX.Compose.Spacer! +static AndroidX.Compose.Spacer.Size(AndroidX.Compose.Dp width, AndroidX.Compose.Dp height) -> AndroidX.Compose.Spacer! +static AndroidX.Compose.Spacer.Weight(float weight, bool fill = true) -> AndroidX.Compose.Spacer! +static AndroidX.Compose.Spacer.Width(AndroidX.Compose.Dp dp) -> AndroidX.Compose.Spacer! static AndroidX.Compose.StaggeredGridCells.Adaptive(float minSizeDp) -> AndroidX.Compose.Foundation.Lazy.Staggeredgrid.IStaggeredGridCells! static AndroidX.Compose.StaggeredGridCells.Fixed(int count) -> AndroidX.Compose.Foundation.Lazy.Staggeredgrid.IStaggeredGridCells! static AndroidX.Compose.StaggeredGridCells.FixedSize(float sizeDp) -> AndroidX.Compose.Foundation.Lazy.Staggeredgrid.IStaggeredGridCells! diff --git a/src/Microsoft.AndroidX.Compose/Spacer.cs b/src/Microsoft.AndroidX.Compose/Spacer.cs index c6af2bb6..50c77a7f 100644 --- a/src/Microsoft.AndroidX.Compose/Spacer.cs +++ b/src/Microsoft.AndroidX.Compose/Spacer.cs @@ -20,4 +20,44 @@ public Spacer() { } /// Convenience overload that sets . public Spacer(Modifier modifier) => Modifier = modifier; + + /// + /// Creates a with a fixed width and no height. Equivalent + /// to new Spacer(Modifier.Width(dp)); the -to- + /// implicit conversion lets callers write Spacer.Width(8). + /// + public static Spacer Width(Dp dp) => new(Modifier.Companion.Width(dp)); + + /// + /// Creates a with a fixed height and no width. Equivalent + /// to new Spacer(Modifier.Height(dp)); the -to- + /// implicit conversion lets callers write Spacer.Height(8). + /// + public static Spacer Height(Dp dp) => new(Modifier.Companion.Height(dp)); + + /// + /// Creates a square of the given size. Equivalent to + /// new Spacer(Modifier.Size(dp)). + /// + public static Spacer Size(Dp dp) => new(Modifier.Companion.Size(dp)); + + /// + /// Creates a rectangular with the given width and height. + /// Equivalent to new Spacer(Modifier.Size(width, height)). + /// + public static Spacer Size(Dp width, Dp height) => new(Modifier.Companion.Size(width, height)); + + /// + /// Creates a that takes a share of the leftover main-axis + /// space inside its parent or — the + /// canonical "push siblings apart" idiom. Equivalent to + /// new Spacer(Modifier.Weight(weight, fill)). As with + /// , only valid inside a Row/Column or + /// Row/Column-shaped scope. + /// + /// Relative share of the leftover space (must be positive). + /// When (the default) the Spacer + /// fills its allotted slot; lets it be smaller. + public static Spacer Weight(float weight, bool fill = true) => + new(Modifier.Companion.Weight(weight, fill)); }