Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/JetNews/HomeCards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -101,7 +101,7 @@ public static Card BuildPopular(Post post, Action<string> onSelectPost) =>
FontWeight = FontWeight.SemiBold,
MaxLines = 2,
},
new Spacer(Modifier.Companion.Weight(1f, fill: true)),
Spacer.Weight(1f),
new Text(post.Metadata.Author)
{
FontSize = 13,
Expand Down
2 changes: 1 addition & 1 deletion samples/JetNews/JetnewsDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};

Expand Down
2 changes: 1 addition & 1 deletion samples/JetNews/PostBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions samples/JetNews/PostScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions samples/Jetchat/Conversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down Expand Up @@ -440,22 +440,22 @@ static ComposableNode BuildSelectorPanel(
MutableState<int> 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,
FontWeight = FontWeight.Medium,
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,
Expand Down
2 changes: 1 addition & 1 deletion samples/Jetchat/JetchatDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions samples/Jetchat/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions samples/Jetchat/RecordButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static ComposableNode BuildRecordingIndicator(
Color = scheme.OnSurface,
},

new Spacer(Modifier.Companion.Width(16)),
Spacer.Width(16),

new Row
{
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion samples/Reply/EmptyComingSoon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
40 changes: 40 additions & 0 deletions src/Microsoft.AndroidX.Compose/Spacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,44 @@ public Spacer() { }

/// <summary>Convenience overload that sets <see cref="ComposableNode.Modifier"/>.</summary>
public Spacer(Modifier modifier) => Modifier = modifier;

/// <summary>
/// Creates a <see cref="Spacer"/> with a fixed width and no height. Equivalent
/// to <c>new Spacer(Modifier.Width(dp))</c>; the <see cref="int"/>-to-<see cref="Dp"/>
/// implicit conversion lets callers write <c>Spacer.Width(8)</c>.
/// </summary>
public static Spacer Width(Dp dp) => new(Modifier.Companion.Width(dp));

/// <summary>
/// Creates a <see cref="Spacer"/> with a fixed height and no width. Equivalent
/// to <c>new Spacer(Modifier.Height(dp))</c>; the <see cref="int"/>-to-<see cref="Dp"/>
/// implicit conversion lets callers write <c>Spacer.Height(8)</c>.
/// </summary>
public static Spacer Height(Dp dp) => new(Modifier.Companion.Height(dp));

/// <summary>
/// Creates a square <see cref="Spacer"/> of the given size. Equivalent to
/// <c>new Spacer(Modifier.Size(dp))</c>.
/// </summary>
public static Spacer Size(Dp dp) => new(Modifier.Companion.Size(dp));

/// <summary>
/// Creates a rectangular <see cref="Spacer"/> with the given width and height.
/// Equivalent to <c>new Spacer(Modifier.Size(width, height))</c>.
/// </summary>
public static Spacer Size(Dp width, Dp height) => new(Modifier.Companion.Size(width, height));

/// <summary>
/// Creates a <see cref="Spacer"/> that takes a share of the leftover main-axis
/// space inside its parent <see cref="Row"/> or <see cref="Column"/> — the
/// canonical "push siblings apart" idiom. Equivalent to
/// <c>new Spacer(Modifier.Weight(weight, fill))</c>. As with
/// <see cref="Modifier.Weight"/>, only valid inside a Row/Column or
/// Row/Column-shaped scope.
/// </summary>
/// <param name="weight">Relative share of the leftover space (must be positive).</param>
/// <param name="fill">When <see langword="true"/> (the default) the Spacer
/// fills its allotted slot; <see langword="false"/> lets it be smaller.</param>
public static Spacer Weight(float weight, bool fill = true) =>
new(Modifier.Companion.Weight(weight, fill));
}
Loading