-
Notifications
You must be signed in to change notification settings - Fork 10
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
[MOB-2012] BezierEmoji 구현 #78
Open
solchan87
wants to merge
4
commits into
channel-io:feature/redesign_bezier
Choose a base branch
from
solchan87:feature/emoji
base: feature/redesign_bezier
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,107 @@ | ||
// | ||
// BezierEmoji.swift | ||
// | ||
// | ||
// Created by Tom on 9/19/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import SDWebImageSwiftUI | ||
|
||
private enum Metric { | ||
static let bottomTrailingPadding: CGFloat = -4 | ||
} | ||
|
||
private enum Constant { | ||
static let emojiUrlString: String = "https://cf.channel.io/asset/emoji/images/80/%@.png" | ||
} | ||
// - MARK: BezierAvatar | ||
public struct BezierEmoji: View { | ||
// MARK: Size | ||
public enum Size { | ||
case pt16 | ||
case pt20 | ||
case pt24 | ||
case pt30 | ||
case pt36 | ||
case pt42 | ||
case pt48 | ||
case pt60 | ||
case pt72 | ||
case pt90 | ||
case pt120 | ||
} | ||
|
||
// MARK: Badge | ||
public enum Badge { | ||
case chat | ||
} | ||
|
||
// MARK: Properties | ||
private let name: String | ||
private let size: Size | ||
private let badge: Badge? | ||
|
||
private var emojiUrl: URL? { | ||
if let encodedEmojiUrlString = String(format: Constant.emojiUrlString, self.name).percentEncode() { | ||
return URL(string: encodedEmojiUrlString) | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
// MARK: Initializer | ||
/// - Parameters: | ||
/// - name: ch-asset 기반으로 emoji 의 file name 을 사용합니다. | ||
/// - emojipedia 를 통해 name을 검색 할 수 있으며, Shortcodes/github 기준으로 사용합니다. | ||
/// - ex) https://emojipedia.org/😄#technical | ||
/// - size: emoji 사이즈는 `16pt`, `20pt`, `24pt`, `30pt`, `36pt`, `42pt`, `48pt`, `60pt`, `72pt`, `90pt`, `120pt` 로 총 11개 사이즈를 가집니다. | ||
/// - emoji의 경우 예외적으로 semantic name 이 아닌, raw 한 수치 그대로 사용합니다. | ||
/// - badge: 이모지의 상태 배지가 포함될 수 있습니다. | ||
/// - chat (public / private) | ||
public init(name: String, size: Size, badge: Badge? = nil) { | ||
self.name = name | ||
self.size = size | ||
self.badge = badge | ||
} | ||
|
||
// MARK: Body | ||
public var body: some View { | ||
WebImage(url: self.emojiUrl) | ||
.resizable() | ||
.scaledToFit() | ||
.frame(length: self.length) | ||
.if(self.badge.isNotNil) { view in | ||
view | ||
.overlay( | ||
BezierChatBadge(size: .medium) | ||
.padding([.bottom, .trailing], Metric.bottomTrailingPadding), | ||
alignment: .bottomTrailing | ||
) | ||
} | ||
} | ||
} | ||
|
||
// - MARK: Style | ||
extension BezierEmoji { | ||
private var length: CGFloat { | ||
switch self.size { | ||
case .pt16: return 16 | ||
case .pt20: return 20 | ||
case .pt24: return 24 | ||
case .pt30: return 30 | ||
case .pt36: return 36 | ||
case .pt42: return 42 | ||
case .pt48: return 48 | ||
case .pt60: return 60 | ||
case .pt72: return 72 | ||
case .pt90: return 90 | ||
case .pt120: return 120 | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
BezierEmoji(name: "+1", size: .pt24, badge: .chat) | ||
} |
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,26 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Tom on 9/19/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Optional { | ||
var isNil: Bool { self == nil } | ||
var isNotNil: Bool { self != nil } | ||
} | ||
|
||
extension Optional where Wrapped == Bool { | ||
var beTrue: Bool { self == true } | ||
var beFalse: Bool { self == false } | ||
} | ||
|
||
extension Optional where Wrapped == String { | ||
public var isNilOrEmpty: Bool { | ||
guard let self else { return true } | ||
|
||
return self.isEmpty | ||
} | ||
} |
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
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
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
24 changes: 24 additions & 0 deletions
24
Examples/SwiftUIExample/SwiftUIExample/Examples/BezierEmojiExample.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,24 @@ | ||
// | ||
// BezierEmojiExample.swift | ||
// SwiftUIExample | ||
// | ||
// Created by Tom on 9/20/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import BezierSwift | ||
|
||
struct BezierEmojiExample: View { | ||
var body: some View { | ||
BezierEmoji( | ||
name: "+1", | ||
size: .pt24, | ||
badge: .chat | ||
) | ||
} | ||
} | ||
|
||
#Preview { | ||
BezierEmojiExample() | ||
} |
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.
emoji 전체를 열거형으로 리스트업 하는 것보다 스트링을 통해서 가져오도록 논의가 되었습니다.