Skip to content
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

feat: Move IKButtons to CoreUI #35

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad",
"version" : "5.8.1"
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
"version" : "5.9.1"
}
},
{
"identity" : "cocoalumberjack",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CocoaLumberjack/CocoaLumberjack",
"state" : {
"revision" : "0188d31089b5881a269e01777be74c7316924346",
"version" : "3.8.0"
"revision" : "4b8714a7fb84d42393314ce897127b3939885ec3",
"version" : "3.8.5"
}
},
{
Expand All @@ -41,26 +41,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-login",
"state" : {
"revision" : "904c1ac39b4db56212302b464a0b2e023d9b5791",
"version" : "6.0.0"
"revision" : "7214a97f73b9b19858d3b3139a2fe47be86e142e",
"version" : "6.0.2"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher",
"state" : {
"revision" : "3ec0ab0bca4feb56e8b33e289c9496e89059dd08",
"version" : "7.10.2"
"revision" : "2ef543ee21d63734e1c004ad6c870255e8716c50",
"version" : "7.12.0"
}
},
{
"identity" : "matomo-sdk-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/matomo-org/matomo-sdk-ios",
"state" : {
"revision" : "15a645e11eaa8053f93749d73ced03da1e56fd01",
"version" : "7.5.2"
"revision" : "a8800d8725fb84bad6b7dea555075f961952bc0a",
"version" : "7.6.0"
}
},
{
Expand All @@ -77,26 +77,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/realm-core.git",
"state" : {
"revision" : "7227d6a447821c28895daa099b6c7cd4c99d461b",
"version" : "13.25.1"
"revision" : "60867846a0aca0c7da5e482282b293236f730216",
"version" : "14.11.0"
}
},
{
"identity" : "realm-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/realm-swift",
"state" : {
"revision" : "836cc4b8619886f979f8961c3f592a82b0741591",
"version" : "10.45.3"
"revision" : "13b12f8665f0c8173693a4d3f6e6d32b5a24d9a9",
"version" : "10.52.2"
}
},
{
"identity" : "sentry-cocoa",
"kind" : "remoteSourceControl",
"location" : "https://github.com/getsentry/sentry-cocoa",
"state" : {
"revision" : "3b9a8e69ca296bd8cd0e317ad7a448e5daf4a342",
"version" : "8.18.0"
"revision" : "5421f94cc859eb65f5ae3866165a053aa634431e",
"version" : "8.32.0"
}
},
{
Expand All @@ -113,17 +113,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SnapKit/SnapKit.git",
"state" : {
"revision" : "f222cbdf325885926566172f6f5f06af95473158",
"version" : "5.6.0"
"revision" : "2842e6e84e82eb9a8dac0100ca90d9444b0307f4",
"version" : "5.7.1"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
"version" : "1.5.2"
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Infomaniak Core UI - iOS
Copyright (C) 2023 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import SwiftUI

@available(iOS 15.0, *)
struct IKButtonLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(spacing: IKPadding.small) {
configuration.icon
configuration.title
}
}
}

@available(iOS 15.0, *)
extension LabelStyle where Self == IKButtonLabelStyle {
static var ikButtonLabel: IKButtonLabelStyle {
IKButtonLabelStyle()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Infomaniak Core UI - iOS
Copyright (C) 2023 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import SwiftUI

@available(iOS 15.0, *)
public struct IKBorderedProminentButtonStyle: ButtonStyle {
@Environment(\.ikButtonLoading) private var isLoading

public func makeBody(configuration: Configuration) -> some View {
configuration.label
.labelStyle(.ikButtonLabel)
.modifier(IKButtonOpacityAnimationModifier(isPressed: configuration.isPressed))
.modifier(IKButtonLoadingModifier(isFilled: true))
.modifier(IKButtonExpandableModifier())
.modifier(IKButtonControlSizeModifier())
.modifier(IKButtonLayout(isInlined: false))
.modifier(IKButtonFilledModifier())
.allowsHitTesting(!isLoading)
}
}

@available(iOS 15.0, *)
public extension ButtonStyle where Self == IKBorderedProminentButtonStyle {
static var ikBorderedProminent: IKBorderedProminentButtonStyle {
return IKBorderedProminentButtonStyle()
}
}

@available(iOS 15.0, *)
#Preview {
NavigationView {
List {
Section("Standard Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
}

Section("Large Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.controlSize(.large)
}

Section("Full Width Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.controlSize(.large)
.ikButtonFullWidth(true)
}

Section("Button With Different Colors") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.ikButtonTheme(
IKButtonTheme(
primary: Color.purple,
secondary: Color.white,
disabledPrimary: Color.gray,
disabledSecondary: Color.white,
error: Color.red,
smallFont: .body,
mediumFont: .headline
)
)
}

Section("Loading Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.ikButtonLoading(true)
}

Section("Disabled Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.disabled(true)
}
}
.buttonStyle(.ikBorderedProminent)
.navigationTitle("IKBorderedProminentButtonStyle")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
Infomaniak Core UI - iOS
Copyright (C) 2023 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import SwiftUI

@available(iOS 15.0, *)
public struct IKBorderlessButtonStyle: ButtonStyle {
@Environment(\.isEnabled) private var isEnabled

@Environment(\.ikButtonTheme) private var theme
@Environment(\.ikButtonLoading) private var isLoading

var isInlined = false

public func makeBody(configuration: Configuration) -> some View {
configuration.label
.labelStyle(.ikButtonLabel)
.foregroundStyle(AnyShapeStyle(foreground(role: configuration.role)))
.modifier(IKButtonLoadingModifier(isFilled: false))
.modifier(IKButtonControlSizeModifier())
.modifier(IKButtonExpandableModifier())
.modifier(IKButtonLayout(isInlined: isInlined))
.contentShape(Rectangle())
.modifier(IKButtonOpacityAnimationModifier(isPressed: configuration.isPressed))
.allowsHitTesting(!isLoading)
}

private func foreground(role: ButtonRole?) -> any ShapeStyle {
if !isEnabled || isLoading {
return theme.disabledPrimary
} else if role == .destructive {
return theme.error
} else {
return theme.primary
}
}
}

@available(iOS 15.0, *)
public extension ButtonStyle where Self == IKBorderlessButtonStyle {
static func ikBorderless(isInlined: Bool) -> IKBorderlessButtonStyle {
return IKBorderlessButtonStyle(isInlined: isInlined)
}

static var ikBorderless: IKBorderlessButtonStyle {
return IKBorderlessButtonStyle()
}
}

@available(iOS 15.0, *)
#Preview {
NavigationView {
List {
Section("Standard Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
}

Section("Destructive Button") {
Button(role: .destructive) {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
}

Section("Small Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.controlSize(.small)
}

Section("Full Width Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.controlSize(.large)
.ikButtonFullWidth(true)
}

Section("Button With Different Color") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.ikButtonTheme(
IKButtonTheme(
primary: Color.purple,
secondary: Color.white,
disabledPrimary: Color.gray,
disabledSecondary: Color.white,
error: Color.red,
smallFont: .body,
mediumFont: .headline
)
)
}

Section("Inlined Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.buttonStyle(.ikBorderless(isInlined: true))
}

Section("Loading Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.ikButtonLoading(true)
}

Section("Disabled Button") {
Button {} label: {
Label("Lorem Ipsum", systemImage: "visionpro")
}
.disabled(true)
}
}
.buttonStyle(.ikBorderless)
.navigationTitle("IKPlainButtonStyle")
}
}
Loading
Loading