Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kubalani committed Dec 28, 2020
1 parent abf3e28 commit b0e7558
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class DrawerVnextDemoController: DemoController {

let leadingEdge: UIRectEdge = view.effectiveUserInterfaceLayoutDirection == .leftToRight ? .left : .right
if leadingEdge == .left {
self.showLeftDrawerDimmedBackgroundButtonTapped()
} else {
self.showRightDrawerDimmedBackgroundButtonTapped()
} else {
self.showLeftDrawerClearBackgroundButtonTapped()
}
}
}
35 changes: 29 additions & 6 deletions ios/FluentUI/DrawerVnext/Drawer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,30 @@ public struct Drawer<Content: View>: View {
}

public var body: some View {
GeometryReader { reader in
GeometryReader { proxy in
HStack {
if state.presentationDirection == .right {
Spacer()
InteractiveSpacer().onTapGesture {
state.isExpanded.toggle()
}
}
content
.frame(width: reader.size.width * percentWidthOfContent)
.frame(width: proxy.portraitOrientationAgnosticSize().width * percentWidthOfContent)
.shadow(color: tokens.shadowColor.opacity(state.isExpanded ? tokens.shadowOpacity : 0),
radius: tokens.shadowBlur,
x: tokens.shadowDepth[0],
y: tokens.shadowDepth[1])
.offset(x: computedOffset(screenSize: reader.size))
.offset(x: computedOffset(screenSize: proxy.portraitOrientationAgnosticSize()))
.animation(backgroundLayerAnimation)

if state.presentationDirection == .left {
Spacer()
InteractiveSpacer().onTapGesture {
state.isExpanded.toggle()
}
}
}
.background(state.isExpanded ? backgroundLayerColor.opacity(backgroundLayerOpacity) : Color.clear)
.gesture(dragGesture(snapWidth: reader.size.width * percentSnapWidthOfScreen))
.gesture(dragGesture(snapWidth: proxy.portraitOrientationAgnosticSize().width * percentSnapWidthOfScreen))
}
}

Expand All @@ -151,6 +155,25 @@ public struct Drawer<Content: View>: View {
}
}

extension GeometryProxy {
func portraitOrientationAgnosticSize() -> CGSize {
let isPortraitMode = self.size.width < self.size.height
if isPortraitMode {
return CGSize(width: self.size.width, height: self.size.height)
} else {
return CGSize(width: self.size.height, height: self.size.width)
}
}
}

public struct InteractiveSpacer: View {
public var body: some View {
ZStack {
Color.black.opacity(0.001)
}
}
}

/**
`DrawerHost` is UIKit wrapper required to host UIViewController as content.
*/
Expand Down

0 comments on commit b0e7558

Please sign in to comment.