Skip to content

Commit

Permalink
Fix embedded sizing (#3200)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski authored Sep 10, 2024
1 parent 441ff93 commit ec1d0a0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 45 deletions.
52 changes: 33 additions & 19 deletions Airship/AirshipCore/Source/EmbeddedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ struct AdoptLayout: SwiftUI.Layout {

/// proposal.replacingUnspecifiedDimensions() uses `10`, so we shall as well
let size = CGSize(width: width ?? 10, height: height ?? 10)

let constraintWidth: CGFloat? = if placement.size.width.isAuto {
nil
} else {
size.width
}

let constraintHeight: CGFloat? = if placement.size.height.isAuto {
nil
} else {
size.height
}

let viewConstraints = ViewConstraints(
width: constraintWidth,
height: constraintHeight
)

DispatchQueue.main.async {
if (self.viewConstraints != viewConstraints) {
self.viewConstraints = viewConstraints
}
}

return size
}

Expand All @@ -48,16 +72,6 @@ struct AdoptLayout: SwiftUI.Layout {
}

func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {

let constraints = ViewConstraints(
width: embeddedSize?.parentWidth ?? bounds.width,
height: embeddedSize?.parentHeight ?? bounds.height
)

DispatchQueue.main.async {
viewConstraints = constraints
}

let viewProposal = ProposedViewSize(
width: size(
constraint: placement.size.width,
Expand Down Expand Up @@ -107,25 +121,25 @@ struct EmbeddedView: View {
height: placement.size.height.calculateSize(self.embeddedSize?.parentHeight)
)

createView(constraints: constraints, placement: placement)
let contentConstraints = constraints.contentConstraints(
placement.size,
contentSize: nil,
margin: placement.margin
)

createView(constraints: contentConstraints, placement: placement)
}
}
}

@MainActor
private func createView(constraints: ViewConstraints, placement: EmbeddedPlacement) -> some View {
let contentConstraints = constraints.contentConstraints(
placement.size,
contentSize: nil,
margin: placement.margin
)

return ViewFactory
.createView(model: layout.view, constraints: contentConstraints)
.createView(model: layout.view, constraints: constraints)
.background(placement.backgroundColor)
.border(placement.border)
.margin(placement.margin)
.constraints(contentConstraints)
.constraints(constraints)
}

private func resolvePlacement(orientation: Orientation, windowSize: WindowSize) -> EmbeddedPlacement {
Expand Down
2 changes: 0 additions & 2 deletions Airship/AirshipCore/Source/Pager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,6 @@ struct Pager: View {
}

private func handleTouch(isPressed: Bool, index: Binding<Int>) {
print("isPressed: \(isPressed)")

self.model.retrieveGestures(type: PagerHoldGesture.self).forEach { gesture in
let behavior = isPressed ? gesture.pressBehavior : gesture.releaseBehavior
handleGestureBehavior(
Expand Down
2 changes: 1 addition & 1 deletion Airship/AirshipCore/Source/TouchViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fileprivate struct TouchViewModifier: ViewModifier {
TapGesture()
)
.gesture(
LongPressGesture(minimumDuration: 0.0)
LongPressGesture(minimumDuration: 0.1)
.sequenced(before: LongPressGesture(minimumDuration: .infinity))
.updating($isPressed) { value, state, transaction in
switch value {
Expand Down
2 changes: 1 addition & 1 deletion Airship/AirshipCore/Source/ViewConstraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct ViewConstraints: Equatable {
parentHeight
)

childHeight = childHeight? .bound(
childHeight = childHeight?.bound(
minValue: childMinHeight,
maxValue: childMaxHeight
)
Expand Down
53 changes: 31 additions & 22 deletions Thomas/Thomas/EmbeddedView/HomeView23Grande.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,43 @@ struct HomeView23Grande: View {
.frame(maxWidth: .infinity)
.background(Color.white)

ScrollView(showsIndicators: false) {
GeometryReader { scrollViewSize in

ScrollView(showsIndicators: false) {

AirshipEmbeddedView(embeddedID: "home_image")
.setAirshipEmbeddedStyle(DismissableStyle())

AirshipEmbeddedView(
embeddedID: "home_image",
embeddedSize: AirshipEmbeddedSize(
parentHeight: scrollViewSize.size.height
)
)

Spacer(minLength: 30)
.setAirshipEmbeddedStyle(DismissableStyle())

VStack(spacing:0) {
FashionMenu(tabIndex: $tabIndex)
Separation()
FashionImages(tabIndex: $tabIndex)
.frame(height: max(300.0, geo.size.height * 0.50))
}

Text("NEW ARRIVALS")
.fontWeight(.bold)
.multilineTextAlignment(.center)

ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing:10) {
Spacer()
Image("23GrandeArrival1")
.resize(width: geo.size.width * 0.40)
Image("23GrandeArrival2")
.resize(width: geo.size.width * 0.40)
Spacer()
Spacer(minLength: 30)

VStack(spacing:0) {
FashionMenu(tabIndex: $tabIndex)
Separation()
FashionImages(tabIndex: $tabIndex)
.frame(height: max(300.0, geo.size.height * 0.50))
}

Text("NEW ARRIVALS")
.fontWeight(.bold)
.multilineTextAlignment(.center)

ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing:10) {
Spacer()
Image("23GrandeArrival1")
.resize(width: geo.size.width * 0.40)
Image("23GrandeArrival2")
.resize(width: geo.size.width * 0.40)
Spacer()
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Thomas/Thomas/Resources/Scenes/Embedded/home_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ presentation:
size:
width: 100%
height: auto
margin:
start: 16
end: 16
top: 16
bottom: 16
embedded_id: home_image

view:
type: pager_controller
identifier: cd21507b-c0b1-4094-9cc6-a1c7e0713c82
Expand Down

0 comments on commit ec1d0a0

Please sign in to comment.