-
Notifications
You must be signed in to change notification settings - Fork 0
[DShape] [DCore] [DButton] Boost with Shape, Button, and Core. #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
81f220f
[DShape] Finish basic implementation of Shape.
lilingxi01 53b26c7
[DVMod] Add adaptation(_:) modifier.
lilingxi01 a321af9
[DVMod] Add onClick(_:) modifier.
lilingxi01 1cefc69
[DVMod] Expand frame() modifier to View protocol.
lilingxi01 ca0a3bc
[DV] Optimize BorderConfiguration initializer.
lilingxi01 22dfcab
[DCore] Finish basic implementation of Core mod.
lilingxi01 a0d9c43
[DBlur] Add basic blur module.
lilingxi01 703f9ad
[DDivider] Add basic divider component.
lilingxi01 c50435c
[View+] Add visibility() modifier support.
lilingxi01 9d9602d
[DBlur] Simply format the code.
lilingxi01 f292ab1
[Frame] Change modifier to avoid ambiguous use.
lilingxi01 88b880f
[Shape] Update with new frame modifier.
lilingxi01 ebde0d6
[DEColor] Add some preset colors.
lilingxi01 e5ee1ce
[DV] Add get border configuration function.
lilingxi01 1d24c7c
[DVManager] Add present type enum.
lilingxi01 1b349d4
[DHaptics] Finish implementation of haptic module.
lilingxi01 da6067a
[DButton] Finish basic implementation of Button.
lilingxi01 f46e45c
[DAnimation] Add basic built-in animations.
lilingxi01 fb468ed
[DButton] Remove scale from configuration.
lilingxi01 9ac9b8b
[DButton] Fix tap animation bug.
lilingxi01 29a8e8a
[DButton] Fix tap animation bug.
lilingxi01 7358a89
[DButton] Remove redundant import.
lilingxi01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Sources/DefinedElements/Animation/Built-ins/DAnimation.Main.swift
This file contains hidden or 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,20 @@ | ||
import SwiftUI | ||
|
||
public class DefinedAnimation { | ||
public static let spring = Animation.spring( | ||
response: 0.80, | ||
dampingFraction: 0.55, | ||
blendDuration: 0.40 | ||
) | ||
} | ||
|
||
public extension DefinedAnimation { | ||
/// - TODO: Customize the duration and bounce rate, compute the values automatically. | ||
static func spring(h: Int) -> Animation { | ||
return Animation.spring( | ||
response: 0.80, | ||
dampingFraction: 0.55, | ||
blendDuration: 0.40 | ||
) | ||
} | ||
} |
This file contains hidden or 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,12 @@ | ||
import SwiftUI | ||
|
||
/// | ||
public struct DefinedBlurBackground : DefinedView { | ||
let opa: Double = DEColor.std.opa | ||
|
||
public var body: some View { | ||
DefinedBlur( | ||
blurStyle: .systemUltraThinMaterial | ||
).overlay(DEColor.blur.light) | ||
} | ||
} |
This file contains hidden or 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,133 @@ | ||
import SwiftUI | ||
|
||
#if os(iOS) | ||
|
||
/// [DE] Blur Module | ||
/// Inspired by: https://github.com/twostraws/VisualEffects/blob/main/Sources/VisualEffects/VisualEffectBlur-iOS.swift | ||
/// | ||
/// - TODO: Rebuild it with DefinedView module. | ||
/// - TODO: Make the macOS version | ||
public struct DefinedBlur<Content: View> : DefinedView { | ||
/// Defaults to .systemMaterial | ||
var blurStyle: UIBlurEffect.Style | ||
|
||
/// Defaults to nil | ||
var vibrancyStyle: UIVibrancyEffectStyle? | ||
|
||
var content: Content | ||
|
||
public init(blurStyle: UIBlurEffect.Style = .systemMaterial, | ||
vibrancyStyle: UIVibrancyEffectStyle? = nil, | ||
@ViewBuilder content: () -> Content) { | ||
self.blurStyle = blurStyle | ||
self.vibrancyStyle = vibrancyStyle | ||
self.content = content() | ||
} | ||
|
||
public var body: some View { | ||
DefinedBlurRepresentable() | ||
|
||
// Representable( | ||
// blurStyle: blurStyle, | ||
// vibrancyStyle: vibrancyStyle, | ||
// content: ZStack { content } | ||
// ) | ||
// .accessibility(hidden: Content.self == EmptyView.self) | ||
} | ||
} | ||
|
||
// MARK: - Representable | ||
|
||
extension DefinedBlur { | ||
struct Representable<Content: View>: UIViewRepresentable { | ||
var blurStyle: UIBlurEffect.Style | ||
var vibrancyStyle: UIVibrancyEffectStyle? | ||
var content: Content | ||
|
||
func makeUIView(context: Context) -> UIVisualEffectView { | ||
context.coordinator.blurView | ||
} | ||
|
||
func updateUIView(_ view: UIVisualEffectView, context: Context) { | ||
context.coordinator.update(content: content, blurStyle: blurStyle, vibrancyStyle: vibrancyStyle) | ||
} | ||
|
||
func makeCoordinator() -> Coordinator { | ||
Coordinator(content: content) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Coordinator | ||
|
||
extension DefinedBlur.Representable { | ||
class Coordinator { | ||
let blurView = UIVisualEffectView() | ||
let vibrancyView = UIVisualEffectView() | ||
let hostingController: UIHostingController<Content> | ||
|
||
init(content: Content) { | ||
hostingController = UIHostingController(rootView: content) | ||
hostingController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
hostingController.view.backgroundColor = nil | ||
blurView.contentView.addSubview(vibrancyView) | ||
|
||
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
vibrancyView.contentView.addSubview(hostingController.view) | ||
vibrancyView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
} | ||
|
||
func update(content: Content, blurStyle: UIBlurEffect.Style, vibrancyStyle: UIVibrancyEffectStyle?) { | ||
hostingController.rootView = content | ||
|
||
let blurEffect = UIBlurEffect(style: blurStyle) | ||
blurView.effect = blurEffect | ||
|
||
if let vibrancyStyle = vibrancyStyle { | ||
vibrancyView.effect = UIVibrancyEffect(blurEffect: blurEffect, style: vibrancyStyle) | ||
} else { | ||
vibrancyView.effect = nil | ||
} | ||
|
||
hostingController.view.setNeedsDisplay() | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Content-less Initializer | ||
|
||
public extension DefinedBlur where Content == EmptyView { | ||
init(blurStyle: UIBlurEffect.Style = .systemMaterial) { | ||
self.init(blurStyle: blurStyle, vibrancyStyle: nil) { | ||
EmptyView() | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
public struct DefinedBlurRepresentable: UIViewRepresentable { | ||
public func makeUIView(context: UIViewRepresentableContext<DefinedBlurRepresentable>) -> UIView { | ||
let view = UIView(frame: .zero) | ||
view.backgroundColor = .clear | ||
let blurEffect = UIBlurEffect(style: .systemUltraThinMaterial) | ||
let blurView = UIVisualEffectView(effect: blurEffect) | ||
blurView.translatesAutoresizingMaskIntoConstraints = false | ||
view.insertSubview(blurView, at: 0) | ||
|
||
NSLayoutConstraint.activate([ | ||
blurView.heightAnchor.constraint(equalTo: view.heightAnchor), | ||
blurView.widthAnchor.constraint(equalTo: view.widthAnchor), | ||
blurView.centerYAnchor.constraint(equalTo: view.centerYAnchor), | ||
blurView.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
]) | ||
|
||
return view | ||
} | ||
|
||
public func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<DefinedBlurRepresentable>) { | ||
guard let effectView = uiView.subviews.first as? UIVisualEffectView else { return } | ||
let blurEffect = UIBlurEffect(style: context.environment.colorScheme == .dark ? .dark : .light) | ||
effectView.effect = blurEffect | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to enhance it later.