Pass UIFont object from React-Native to Swift

Viewed 56

I have a native Swift component that is managed by a React-Native view. From my RN view I would like to pass an UIFont object which should then be avaiable in Swift. With the following implementation the property in swift gets called but does not get the values from the RN view.

<NativeSwiftView
     uiFontStyle={{ name: "Arial", size: 15 }}
/>

The property is exposed by objective c like this:

@interface RCT_EXTERN_MODULE(RCTNativeSwiftViewManager, RCTViewManager)
    RCT_EXPORT_VIEW_PROPERTY(uiFontStyle, UIFont)
@end

In Swift the property looks like this:

@objc var uiFontStyle = UIFont(name: "", size: 0) {   
    didSet {
        print("Did set: ", uiFontStyle!)
        self.font = uiFontStyle!
    }
  }

This gets printed to the console after didSet runs:

Did set:  <UICTFont: 0x7fef00c2b2b0> font-family: ".SFUI-Regular"; font-weight: normal; font-style: normal; font-size: 14.00pt

Why are the values of the print statement not the ones I set in my RN view?

0 Answers
Related