Skip to content

Instantly share code, notes, and snippets.

@CodeSlicing
Last active January 18, 2020 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeSlicing/6873695fd0113c27d5cdd8591eca9d1d to your computer and use it in GitHub Desktop.
Save CodeSlicing/6873695fd0113c27d5cdd8591eca9d1d to your computer and use it in GitHub Desktop.
Demonstrates the use of relativeOffset modifier
//
// RelativeOffsetDemo.swift
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
// AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Created by Adam Fordyce on 12/01/2020.
// Copyright © 2020 Adam Fordyce. All rights reserved.
//
import SwiftUI
import PureSwiftUI
private let boxSize = 300
struct RelativeOffsetDemo: View {
@State private var open = false
var body: some View {
VStack() {
ZStack {
LargeTitleText("Relative\nOffset!\n😎", .bold)
.align(.center)
Group {
VStack(spacing: 0) {
Frame(boxSize, boxSize / 2, .blue)
.borderColor(Color(white: 0.1))
.relativeYOffsetIf(self.open, -0.8)
Frame(boxSize, boxSize / 2, .blue)
.borderColor(Color(white: 0.1))
.relativeYOffsetIf(self.open, 0.8)
}
HStack(spacing: 0) {
Frame(boxSize / 2, boxSize, .blue)
.borderColor(Color(white: 0.1))
.relativeXOffsetIf(self.open, -0.8)
Frame(boxSize / 2, boxSize, .blue)
.borderColor(Color(white: 0.1))
.relativeXOffsetIf(self.open, 0.8)
}
}
.shadowIf(open, color: Color.black.opacity(0.6), radius: 5)
}
.cutoutRectangle()
Button(action: {
withAnimation(.easeInOut(duration: 2)) {
self.open.toggle()
}
}) {
TitleText("Toggle", .white)
.frame(150, 50)
.clipRoundedRectangleWithStroke(10, .black, lineWidth: 2, fill: Color.blue)
}
}
}
}
struct RevealWithOffsetTest_Previews: PreviewProvider {
struct RevealWithOffsetTest_Harness: View {
var body: some View {
RelativeOffsetDemo().previewDevice(.iPhone_8)
}
}
static var previews: some View {
RevealWithOffsetTest_Harness()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment