Skip to content

Commit

Permalink
fix uifont converter and impl converters for text align and keyboard …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
RyosukeCla committed Dec 18, 2023
1 parent bd86375 commit 4f475c8
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions ios/Nativebrik/Nativebrik/utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,16 @@ func parseFontDesign(_ data: FontDesign?) -> UIFontDescriptor.SystemDesign {
}
}

func parseTextBlockDataToUIFont(_ data: UITextBlockData?) -> UIFont {
switch data {
case .none:
return UIFont.systemFont(
ofSize: 16,
weight: parseFontWeight(nil)
)
case .some(let text):
let size = CGFloat(text.size ?? 16)
let systemFont = UIFont.systemFont(ofSize: size, weight: parseFontWeight(data?.weight))
let font: UIFont
if let descriptor = systemFont.fontDescriptor.withDesign(parseFontDesign(data?.design)) {
font = UIFont(descriptor: descriptor, size: size)
} else {
font = systemFont
}
return font
func parseTextBlockDataToUIFont(_ size: Int?, _ weight: FontWeight?, _ design: FontDesign?) -> UIFont {
let size = CGFloat(size ?? 16)
let systemFont = UIFont.systemFont(ofSize: size, weight: parseFontWeight(weight))
let font: UIFont
if let descriptor = systemFont.fontDescriptor.withDesign(parseFontDesign(design)) {
font = UIFont(descriptor: descriptor, size: size)
} else {
font = systemFont
}
return font
}

func parseFrameDataToUIKitUIEdgeInsets(_ data: FrameData?) -> UIEdgeInsets {
Expand Down Expand Up @@ -184,6 +176,38 @@ func parseModalScreenSize(_ data: ModalScreenSize?) -> [UISheetPresentationContr
}
}

func parseTextAlign(_ data: TextAlign?) -> NSTextAlignment {
switch data {
case .LEFT:
return .left
case .CENTER:
return .center
case .RIGHT:
return .right
default:
return .natural
}
}

func parserKeyboardType(_ data: UITextInputKeyboardType?) -> UIKeyboardType {
switch data {
case .ALPHABET:
return .alphabet
case .ASCII:
return .asciiCapable
case .DECIMAL:
return .decimalPad
case .NUMBER:
return .numberPad
case .URI:
return .URL
case .EMAIL:
return .emailAddress
default:
return .default
}
}

func parseImageContentMode(_ data: ImageContentMode?) -> UIView.ContentMode {
switch data {
case .FIT:
Expand Down

0 comments on commit 4f475c8

Please sign in to comment.