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
| void main() { | |
| final engine = CombustionEngine(); | |
| final car = Car(engine); | |
| car.start(); | |
| car.stop(); | |
| } | |
| class Car { | |
| final Engine engine; | |
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
| import UIKit | |
| public struct Shadow { | |
| public var color: UIColor | |
| public var offset: CGSize | |
| public var radius: CGFloat | |
| public var spread: CGFloat | |
| public init(color: UIColor, | |
| offset: CGSize, |
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
| { | |
| "shadow": { | |
| "1": { | |
| "value": [ | |
| { | |
| "color": "#0000000a", | |
| "type": "dropShadow", | |
| "x": "0", | |
| "y": "4", | |
| "blur": "8", |
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
| let gradient = BaseGradient(colors: [.red, .blue], angle: 45, locations: [0.0, 1.0]) | |
| view.setGradientBackgroundColor(gradient: grad) | |
| // หรือจะใช้จาก DesignToken แบบนี้ก็ได้เลยเหมือนกัน | |
| view.setGradientBackgroundColor(gradient: BitkubColor.share.gradient.yellowgreen) | |
| // ภาพสุดท้ายที่ต้องการคือการดึงจาก alias โดยเอา global token ไป map อีกที แบบนี้ (ยังไม่ได้ทำ) | |
| view.setGradientBackgroundColor(gradient: theme.colors.gradient.primary) |
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
| extension UIView { | |
| // ตรงนี้ overload function ข้างล่างนะ | |
| public func setGradientBackgroundColor(gradient: BaseGradient) { | |
| setGradientBackgroundColor( | |
| colors: gradient.colors, | |
| angle: gradient.angle, | |
| location: gradient.locations | |
| ) | |
| } | |
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
| const generateData = (json, mark, depth = 0) => { | |
| let space = generateSpace(depth) | |
| let data = createStructHeader(mark, space) | |
| Object.keys(json).forEach(key => { | |
| if(json[key].isSource){ | |
| if(mark !== 'gradient') { | |
| data += `${space} public var ${isFinite(key) ? mark : ''}${key} = ${json[key].value}\n` | |
| } else { | |
| const value = json[key].original.value | |
| const cleanText = value.replace('linear-gradient(', '').replace(')', '').split(',') |
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
| public struct BaseGradient { | |
| var colors: [UIColor] | |
| var angle: CGFloat | |
| var locations: [NSNumber] | |
| } |
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
| func tanx(_ 𝜽: CGFloat) -> CGFloat { | |
| return tan(𝜽 * CGFloat.pi / 180) | |
| } | |
| public func calculatePoints(for angle: CGFloat) { | |
| var ang = (-angle).truncatingRemainder(dividingBy: 360) | |
| if ang < 0 { ang = 360 + ang } |
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
| // Gradient เป็น CAGradientLayer นะคับ | |
| gradient.colors: [CGColor] // สี | |
| gradient.locations: [NSNumber] // ที่อยู่ของแต่ละสี | |
| gradient.startPoint: CGPoint // จุดเริ่มลาก gradient | |
| gradient.endPoint: CGPoint // จุดสิ้นสุด gradient |
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
| import UIKit | |
| public struct BitkubColor { | |
| public static let share = BitkubColor() | |
| public var black = UIColor(red: 0.047, green: 0.055, blue: 0.047, alpha: 1) | |
| public var white = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1) | |
| public var transparent = Transparent() | |
| public struct Transparent { | |
| public var green = Green() | |
| public struct Green { |
NewerOlder