Skip to content

Commit

Permalink
[Layout] - Implemented VStack and HStack (Resolves #22) (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll authored Jun 2, 2024
1 parent ef6b2e7 commit 70ac28f
Show file tree
Hide file tree
Showing 31 changed files with 824 additions and 45 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/pr_validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Validate pull requests
on: [pull_request]
jobs:
analyze:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
# Checkout the PR branch
- uses: actions/checkout@v3

# Setup Flutter environment
- uses: subosito/flutter-action@v2
with:
channel: "stable"
architecture: x64

# Download all the packages that the app uses
- run: flutter pub get

# Enforce lint rules
- run: flutter analyze

test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
# Checkout the PR branch
- uses: actions/checkout@v3

# Setup Flutter environment
- uses: subosito/flutter-action@v2
with:
channel: "stable"
architecture: x64

# Download all the packages that the app uses
- run: flutter pub get

# Run all tests
- run: flutter test --exclude-tags=golden

test-goldens:
runs-on: macos-latest
defaults:
run:
working-directory: ./
steps:
# Checkout the PR branch
- uses: actions/checkout@v3

# Setup Flutter environment
- uses: subosito/flutter-action@v2
with:
channel: "stable"
architecture: x64

# Download all the packages that the app uses
- run: flutter pub get

# Run all tests
- run: flutter test --tags=golden
3 changes: 3 additions & 0 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tags:
golden:

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
C9CAE2B12AE1065F0042DBC7 /* ControlsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CAE2B02AE1065F0042DBC7 /* ControlsPage.swift */; };
C9CAE2B32AE1066B0042DBC7 /* MotionPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CAE2B22AE1066B0042DBC7 /* MotionPage.swift */; };
C9CAE2BB2AE1089A0042DBC7 /* LayoutsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CAE2BA2AE1089A0042DBC7 /* LayoutsPage.swift */; };
C9FB17562C0C4AB4004479AA /* HStackExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FB17552C0C4AB4004479AA /* HStackExamples.swift */; };
C9FB17582C0C4D25004479AA /* ZStackExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9FB17572C0C4D25004479AA /* ZStackExamples.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -74,6 +76,8 @@
C9CAE2B02AE1065F0042DBC7 /* ControlsPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlsPage.swift; sourceTree = "<group>"; };
C9CAE2B22AE1066B0042DBC7 /* MotionPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MotionPage.swift; sourceTree = "<group>"; };
C9CAE2BA2AE1089A0042DBC7 /* LayoutsPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutsPage.swift; sourceTree = "<group>"; };
C9FB17552C0C4AB4004479AA /* HStackExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HStackExamples.swift; sourceTree = "<group>"; };
C9FB17572C0C4D25004479AA /* ZStackExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZStackExamples.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -264,6 +268,8 @@
children = (
C9CAE2BA2AE1089A0042DBC7 /* LayoutsPage.swift */,
C902DDE42AE38C8A00242DBA /* VStackExamples.swift */,
C9FB17552C0C4AB4004479AA /* HStackExamples.swift */,
C9FB17572C0C4D25004479AA /* ZStackExamples.swift */,
);
path = layouts;
sourceTree = "<group>";
Expand Down Expand Up @@ -410,9 +416,11 @@
C9CAE2BB2AE1089A0042DBC7 /* LayoutsPage.swift in Sources */,
C9CAE2B12AE1065F0042DBC7 /* ControlsPage.swift in Sources */,
C9CAE2AB2ADFB1480042DBC7 /* PrimitivesPage.swift in Sources */,
C9FB17582C0C4D25004479AA /* ZStackExamples.swift in Sources */,
C902DDE72AE3904400242DBA /* TodoPage.swift in Sources */,
C9CAE2B32AE1066B0042DBC7 /* MotionPage.swift in Sources */,
B3DD96702B66513800F66E9F /* ImageLocalizationPage.swift in Sources */,
C9FB17562C0C4AB4004479AA /* HStackExamples.swift in Sources */,
C9CAE2812AC23AB40042DBC7 /* swift_ui_galleryApp.swift in Sources */,
C902DDE52AE38C8A00242DBA /* VStackExamples.swift in Sources */,
C9CAE2AF2AE106540042DBC7 /* ScaffoldsPage.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import SwiftUI

struct HStackLeadingAlignedPage : View {
var body: some View {
HStack(alignment: .top) {
Text("First\nSecond")
Text("Third")
Text("Fourth\nFifth\nSixth")
}
}
}

struct HStackCenterAlignedPage : View {
var body: some View {
HStack(alignment: .center) {
Text("First\nSecond")
Text("Third")
Text("Fourth\nFifth\nSixth")
}
}
}

struct HStackTrailingAlignedPage : View {
var body: some View {
HStack(alignment: .bottom) {
Text("First\nSecond")
Text("Third")
Text("Fourth\nFifth\nSixth")
}
}
}

struct HStackExceedsAvailableSpacePage : View {
var body: some View {
HStack() {
Rectangle()
.foregroundColor(Color.red)
.frame(width: 100, height: .infinity)
Rectangle()
.foregroundColor(Color.green)
.frame(width: 100, height: .infinity)
Rectangle()
.foregroundColor(Color.blue)
.frame(width: 100, height: .infinity)
Rectangle()
.foregroundColor(Color.purple)
.frame(width: 100, height: .infinity)
Rectangle()
.foregroundColor(Color.orange)
.frame(width: 100, height: .infinity)
Rectangle()
.foregroundColor(Color.cyan)
.frame(width: 100, height: .infinity)
}
}
}


struct HStackTopAlignedPage_Previews: PreviewProvider {
static var previews: some View {
HStackLeadingAlignedPage()
// HStackCenterAlignedPage()
// HStackTrailingAlignedPage()
// HStackExceedsAvailableSpacePage()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ struct LayoutsPage: View {
List {
Section() {
NavigationLink {
VStackTopAlignedPage()
VStackLeadingAlignedPage()
} label: {
Text("Top Aligned")
}

NavigationLink {
VStackMiddleAlignedPage()
VStackCenterAlignedPage()
} label: {
Text("Middle Aligned")
}

NavigationLink {
VStackBottomAlignedPage()
VStackTrailingAlignedPage()
} label: {
Text("Bottom Aligned")
}

NavigationLink {
VStackExceedsAvailableSpaceAlignedPage()
VStackExceedsAvailableSpacePage()
} label: {
Text("Exceeds available space")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
import SwiftUI

struct VStackTopAlignedPage : View {
struct VStackLeadingAlignedPage : View {
var body: some View {
VStack() {
VStack(alignment: .leading) {
Text("First")
Text("Second")
Text("Third")

Spacer()
}
}
}

struct VStackMiddleAlignedPage : View {
struct VStackCenterAlignedPage : View {
var body: some View {
VStack() {
VStack(alignment: .center) {
Text("First")
Text("Second")
Text("Third")
}
}
}

struct VStackBottomAlignedPage : View {
struct VStackTrailingAlignedPage : View {
var body: some View {
VStack() {
Spacer()

VStack(alignment: .trailing) {
Text("First")
Text("Second")
Text("Third")
}
}
}

struct VStackExceedsAvailableSpaceAlignedPage : View {
struct VStackExceedsAvailableSpacePage : View {
var body: some View {
VStack() {
Rectangle()
Expand Down Expand Up @@ -62,6 +58,9 @@ struct VStackExceedsAvailableSpaceAlignedPage : View {

struct VStackTopAlignedPage_Previews: PreviewProvider {
static var previews: some View {
VStackExceedsAvailableSpaceAlignedPage()
// VStackLeadingAlignedPage()
// VStackCenterAlignedPage()
// VStackTrailingAlignedPage()
VStackExceedsAvailableSpacePage()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import SwiftUI

struct ZStackStaggeredSquares : View {
let colors: [Color] =
[.red, .orange, .yellow, .green, .blue, .purple]

var body: some View {
ZStack {
ForEach(0..<colors.count) {
Rectangle()
.fill(colors[$0])
.frame(width: 100, height: 100)
.offset(x: CGFloat($0) * 10.0,
y: CGFloat($0) * 10.0)
}
}
}
}

struct ZStackTopAlignedPage_Previews: PreviewProvider {
static var previews: some View {
ZStackStaggeredSquares()
}
}
2 changes: 1 addition & 1 deletion example/lib/collections/collection_examples.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:example/infrastructure/InventoryPage.dart';
import 'package:example/infrastructure/inventory_page.dart';
import 'package:example/infrastructure/not_built_yet_page.dart';
import 'package:flutter/cupertino.dart';

Expand Down
2 changes: 1 addition & 1 deletion example/lib/controls/controls_examples.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:example/infrastructure/InventoryPage.dart';
import 'package:example/infrastructure/inventory_page.dart';
import 'package:example/infrastructure/not_built_yet_page.dart';
import 'package:flutter/cupertino.dart';

Expand Down
26 changes: 26 additions & 0 deletions example/lib/demo_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/cupertino.dart';

WidgetBuilder createDemo(Widget child) {
return (BuildContext context) {
return DemoScreen(child: child);
};
}

class DemoScreen extends StatelessWidget {
const DemoScreen({
super.key,
required this.child,
});

final Widget child;

@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(),
child: SafeArea(
child: child,
),
);
}
}
2 changes: 1 addition & 1 deletion example/lib/infrastructure/not_built_yet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Follow @FlutterBounties on Twitter to stay up to date.
''';
}

Widget notBuiltYetPageBuilder(BuildContext) => const NotBuiltYetPage();
Widget notBuiltYetPageBuilder(BuildContext context) => const NotBuiltYetPage();
Loading

0 comments on commit 70ac28f

Please sign in to comment.