Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
xx messenger iOS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
xx messenger iOS
Commits
8dcf6a2f
Commit
8dcf6a2f
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Add SwiftUI extension for CapsuleButton
parent
5d7d96fd
No related branches found
Branches containing commit
No related tags found
1 merge request
!88
HUD feature
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Sources/Shared/Views/CapsuleButton.swift
+79
-14
79 additions, 14 deletions
Sources/Shared/Views/CapsuleButton.swift
with
79 additions
and
14 deletions
Sources/Shared/Views/CapsuleButton.swift
+
79
−
14
View file @
8dcf6a2f
import
UIKit
import
AppResources
import
AppResources
import
Combine
import
SwiftUI
import
UIKit
public
struct
CapsuleButtonModel
{
public
struct
CapsuleButtonModel
{
public
var
title
:
String
public
var
title
:
String
public
var
accessibility
:
String
?
public
var
accessibility
:
String
?
public
var
style
:
CapsuleButtonStyle
public
var
style
:
CapsuleButtonStyle
public
init
(
public
init
(
title
:
String
,
title
:
String
,
style
:
CapsuleButtonStyle
,
style
:
CapsuleButtonStyle
,
...
@@ -33,7 +35,7 @@ public extension CapsuleButtonStyle {
...
@@ -33,7 +35,7 @@ public extension CapsuleButtonStyle {
titleColor
:
Asset
.
brandPrimary
.
color
,
titleColor
:
Asset
.
brandPrimary
.
color
,
disabledTitleColor
:
Asset
.
neutralWhite
.
color
.
withAlphaComponent
(
0.5
)
disabledTitleColor
:
Asset
.
neutralWhite
.
color
.
withAlphaComponent
(
0.5
)
)
)
static
let
brandColored
=
CapsuleButtonStyle
(
static
let
brandColored
=
CapsuleButtonStyle
(
fill
:
.
color
(
Asset
.
brandPrimary
.
color
),
fill
:
.
color
(
Asset
.
brandPrimary
.
color
),
borderWidth
:
0
,
borderWidth
:
0
,
...
@@ -41,7 +43,7 @@ public extension CapsuleButtonStyle {
...
@@ -41,7 +43,7 @@ public extension CapsuleButtonStyle {
titleColor
:
Asset
.
neutralWhite
.
color
,
titleColor
:
Asset
.
neutralWhite
.
color
,
disabledTitleColor
:
Asset
.
neutralWhite
.
color
disabledTitleColor
:
Asset
.
neutralWhite
.
color
)
)
static
let
red
=
CapsuleButtonStyle
(
static
let
red
=
CapsuleButtonStyle
(
fill
:
.
color
(
Asset
.
accentDanger
.
color
),
fill
:
.
color
(
Asset
.
accentDanger
.
color
),
borderWidth
:
0
,
borderWidth
:
0
,
...
@@ -49,7 +51,7 @@ public extension CapsuleButtonStyle {
...
@@ -49,7 +51,7 @@ public extension CapsuleButtonStyle {
titleColor
:
Asset
.
neutralWhite
.
color
,
titleColor
:
Asset
.
neutralWhite
.
color
,
disabledTitleColor
:
Asset
.
neutralWhite
.
color
disabledTitleColor
:
Asset
.
neutralWhite
.
color
)
)
static
let
seeThroughWhite
=
CapsuleButtonStyle
(
static
let
seeThroughWhite
=
CapsuleButtonStyle
(
fill
:
.
color
(
UIColor
.
clear
),
fill
:
.
color
(
UIColor
.
clear
),
borderWidth
:
2
,
borderWidth
:
2
,
...
@@ -57,7 +59,7 @@ public extension CapsuleButtonStyle {
...
@@ -57,7 +59,7 @@ public extension CapsuleButtonStyle {
titleColor
:
Asset
.
neutralWhite
.
color
,
titleColor
:
Asset
.
neutralWhite
.
color
,
disabledTitleColor
:
Asset
.
neutralWhite
.
color
.
withAlphaComponent
(
0.5
)
disabledTitleColor
:
Asset
.
neutralWhite
.
color
.
withAlphaComponent
(
0.5
)
)
)
static
let
seeThrough
=
CapsuleButtonStyle
(
static
let
seeThrough
=
CapsuleButtonStyle
(
fill
:
.
color
(
UIColor
.
clear
),
fill
:
.
color
(
UIColor
.
clear
),
borderWidth
:
2
,
borderWidth
:
2
,
...
@@ -65,7 +67,7 @@ public extension CapsuleButtonStyle {
...
@@ -65,7 +67,7 @@ public extension CapsuleButtonStyle {
titleColor
:
Asset
.
brandPrimary
.
color
,
titleColor
:
Asset
.
brandPrimary
.
color
,
disabledTitleColor
:
Asset
.
brandPrimary
.
color
.
withAlphaComponent
(
0.5
)
disabledTitleColor
:
Asset
.
brandPrimary
.
color
.
withAlphaComponent
(
0.5
)
)
)
static
let
simplestColoredRed
=
CapsuleButtonStyle
(
static
let
simplestColoredRed
=
CapsuleButtonStyle
(
fill
:
.
color
(
UIColor
.
clear
),
fill
:
.
color
(
UIColor
.
clear
),
borderWidth
:
0
,
borderWidth
:
0
,
...
@@ -73,7 +75,7 @@ public extension CapsuleButtonStyle {
...
@@ -73,7 +75,7 @@ public extension CapsuleButtonStyle {
titleColor
:
Asset
.
accentDanger
.
color
,
titleColor
:
Asset
.
accentDanger
.
color
,
disabledTitleColor
:
Asset
.
brandDefault
.
color
.
withAlphaComponent
(
0.5
)
disabledTitleColor
:
Asset
.
brandDefault
.
color
.
withAlphaComponent
(
0.5
)
)
)
static
let
simplestColoredBrand
=
CapsuleButtonStyle
(
static
let
simplestColoredBrand
=
CapsuleButtonStyle
(
fill
:
.
color
(
UIColor
.
clear
),
fill
:
.
color
(
UIColor
.
clear
),
borderWidth
:
0
,
borderWidth
:
0
,
...
@@ -107,9 +109,13 @@ public final class CapsuleButton: UIButton {
...
@@ -107,9 +109,13 @@ public final class CapsuleButton: UIButton {
$0
.
width
.
greaterThanOrEqualTo
(
minimumWidth
)
$0
.
width
.
greaterThanOrEqualTo
(
minimumWidth
)
}
}
}
}
required
init
?(
coder
:
NSCoder
)
{
nil
}
required
init
?(
coder
:
NSCoder
)
{
nil
}
public
override
var
intrinsicContentSize
:
CGSize
{
CGSize
(
width
:
minimumWidth
,
height
:
height
)
}
public
func
set
(
public
func
set
(
style
:
CapsuleButtonStyle
,
style
:
CapsuleButtonStyle
,
title
:
String
,
title
:
String
,
...
@@ -118,25 +124,84 @@ public final class CapsuleButton: UIButton {
...
@@ -118,25 +124,84 @@ public final class CapsuleButton: UIButton {
setTitle
(
title
,
for
:
.
normal
)
setTitle
(
title
,
for
:
.
normal
)
accessibilityIdentifier
=
accessibility
accessibilityIdentifier
=
accessibility
layer
.
borderWidth
=
style
.
borderWidth
layer
.
borderWidth
=
style
.
borderWidth
if
let
color
=
style
.
borderColor
{
if
let
color
=
style
.
borderColor
{
layer
.
borderColor
=
color
.
cgColor
layer
.
borderColor
=
color
.
cgColor
}
}
setBackgroundImage
(
style
.
fill
,
for
:
.
normal
)
setBackgroundImage
(
style
.
fill
,
for
:
.
normal
)
setTitleColor
(
style
.
titleColor
,
for
:
.
normal
)
setTitleColor
(
style
.
titleColor
,
for
:
.
normal
)
setTitleColor
(
style
.
disabledTitleColor
,
for
:
.
disabled
)
setTitleColor
(
style
.
disabledTitleColor
,
for
:
.
disabled
)
}
}
public
func
setStyle
(
_
style
:
CapsuleButtonStyle
)
{
public
func
setStyle
(
_
style
:
CapsuleButtonStyle
)
{
layer
.
borderWidth
=
style
.
borderWidth
layer
.
borderWidth
=
style
.
borderWidth
if
let
color
=
style
.
borderColor
{
if
let
color
=
style
.
borderColor
{
layer
.
borderColor
=
color
.
cgColor
layer
.
borderColor
=
color
.
cgColor
}
}
setBackgroundImage
(
style
.
fill
,
for
:
.
normal
)
setBackgroundImage
(
style
.
fill
,
for
:
.
normal
)
setTitleColor
(
style
.
titleColor
,
for
:
.
normal
)
setTitleColor
(
style
.
titleColor
,
for
:
.
normal
)
setTitleColor
(
style
.
disabledTitleColor
,
for
:
.
disabled
)
setTitleColor
(
style
.
disabledTitleColor
,
for
:
.
disabled
)
}
}
}
}
extension
CapsuleButton
{
public
struct
SwiftUIView
:
UIViewRepresentable
{
public
final
class
Coordinator
{
init
(
view
:
CapsuleButton
.
SwiftUIView
)
{
self
.
view
=
view
}
var
view
:
CapsuleButton
.
SwiftUIView
var
cancellables
=
Set
<
AnyCancellable
>
()
}
public
init
(
height
:
CGFloat
=
55.0
,
minimumWidth
:
CGFloat
=
200
,
style
:
CapsuleButtonStyle
,
title
:
String
,
accessibility
:
String
?
=
nil
,
action
:
@escaping
()
->
Void
)
{
self
.
height
=
height
self
.
minimumWidth
=
minimumWidth
self
.
style
=
style
self
.
title
=
title
self
.
accessibility
=
accessibility
self
.
action
=
action
}
let
height
:
CGFloat
let
minimumWidth
:
CGFloat
var
style
:
CapsuleButtonStyle
var
title
:
String
var
accessibility
:
String
?
var
action
:
()
->
Void
public
func
makeCoordinator
()
->
Coordinator
{
Coordinator
(
view
:
self
)
}
public
func
makeUIView
(
context
:
Context
)
->
CapsuleButton
{
let
uiView
=
CapsuleButton
(
height
:
height
,
minimumWidth
:
minimumWidth
)
uiView
.
publisher
(
for
:
.
touchUpInside
)
.
sink
{
context
.
coordinator
.
view
.
action
()
}
.
store
(
in
:
&
context
.
coordinator
.
cancellables
)
return
uiView
}
public
func
updateUIView
(
_
uiView
:
CapsuleButton
,
context
:
Context
)
{
uiView
.
set
(
style
:
style
,
title
:
title
,
accessibility
:
accessibility
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment