about summary refs log tree commit diff
path: root/modules/react-native-ui-text-view/ios/RNUITextViewChildShadow.swift
blob: 09119a369b60b257dbf4418292c5f5e4aa2b6489 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// We want all of our props to be available in the child's shadow view so we
// can create the attributed text before mount and calculate the needed size
// for the view.
class RNUITextViewChildShadow: RCTShadowView {
  @objc var text: String = ""
  @objc var color: UIColor = .black
  @objc var fontSize: CGFloat = 16.0
  @objc var fontStyle: String = "normal"
  @objc var fontWeight: String = "normal"
  @objc var letterSpacing: CGFloat = 0.0
  @objc var lineHeight: CGFloat = 0.0
  @objc var pointerEvents: NSString?

  override func isYogaLeafNode() -> Bool {
    return true
  }

  override func didSetProps(_ changedProps: [String]!) {
    guard let superview = self.superview as? RNUITextViewShadow else {
      return
    }

    if !YGNodeIsDirty(superview.yogaNode) {
      superview.setAttributedText()
    }
  }

  func getFontWeight() -> UIFont.Weight {
    switch self.fontWeight {
    case "bold":
      return .bold
    case "normal":
      return .regular
    case "100":
      return .ultraLight
    case "200":
      return .ultraLight
    case "300":
      return .light
    case "400":
      return .regular
    case "500":
      return .medium
    case "600":
      return .semibold
    case "700":
      return .semibold
    case "800":
      return .bold
    case "900":
      return .heavy
    default:
      return .regular
    }
  }
}