forked from Dimillian/ACHNBrowserUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Dimillian#341 from renaudjenny/feat/variants-add-r…
…ounded-corner-on-top feat(Variants): add rounded corner on top of the view
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
ACHNBrowserUI/ACHNBrowserUI/views/shared/RoundedRectangleOnTop.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// RoundedRectangleOnTop.swift | ||
// ACHNBrowserUI | ||
// | ||
// Created by Renaud JENNY on 30/01/2021. | ||
// Copyright © 2021 Thomas Ricouard. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct RoundedRectangleOnTop: Shape { | ||
let cornerRadius: CGFloat | ||
|
||
func path(in rect: CGRect) -> Path { | ||
var path = Path() | ||
|
||
// Top left corner | ||
path.move(to: CGPoint(x: rect.minX, y: cornerRadius)) | ||
path.addQuadCurve( | ||
to: CGPoint(x: cornerRadius, y: rect.minY), | ||
control: CGPoint(x: rect.minX, y: rect.minY) | ||
) | ||
// Top right corner | ||
path.addLine(to: CGPoint(x: rect.maxX - cornerRadius, y: rect.minY)) | ||
path.addQuadCurve( | ||
to: CGPoint(x: rect.maxX, y: rect.minY + cornerRadius), | ||
control: CGPoint(x: rect.maxX, y: rect.minY) | ||
) | ||
|
||
// Rest of the rectangle | ||
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY)) | ||
path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY)) | ||
path.closeSubpath() | ||
|
||
return path | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct RoundedRectangleOnTop_Previews: PreviewProvider { | ||
static var previews: some View { | ||
RoundedRectangleOnTop(cornerRadius: 20) | ||
.frame(width: 300, height: 100) | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters