Monday, June 17, 2024
HomeiOS Developmentios - PKCanvasView not displaying when added as a subview

ios – PKCanvasView not displaying when added as a subview


I’m making an attempt to combine the PKCanvasView to a React Native app however when I attempt to add the canvasView as a subView it would not present. It solely works if I return it straight.

Right here is my code.

// BBNativePencilManager.swift
// import PencilKit;

@objc(BBNativePencilManager)
class BBNativePencilManager: RCTViewManager {
  override func view() -> UIView {
//    let canvasView = PKCanvasView();
//    let drawing = PKDrawing()
//    canvasView.drawing = drawing;
//    if #out there(iOS 14.0, *) {
//      canvasView.drawingPolicy = .anyInput
//    }
//    if (theme == "darkish") {
//      canvasView.overrideUserInterfaceStyle = .darkish;
//    } else {
//      canvasView.overrideUserInterfaceStyle = .mild;
//    }
//    canvasView.isOpaque = false;
//    canvasView.backgroundColor = .clear;
//    canvasView.isMultipleTouchEnabled = true;
//    canvasView.backgroundColor = .yellow
//    canvasView.instrument = PKInkingTool(.pen, coloration: UIColor.black, width: 5)
//    canvasView.becomeFirstResponder()
//    return canvasView;
//    The above code works appropriately
    return BBNativePencilView(); // <-- this doesn't work
  }
  
  override static func requiresMainQueueSetup() -> Bool {
    return true
  }
}

And the BBNativePencilView

// BBNativePencilView.swift
import UIKit
import PencilKit


class BBNativePencilView: UIView {

  override init(body: CGRect) {
    tremendous.init(body: body)
    self.addSubview(canvas)
  }

  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been carried out")
  }
  
  lazy var canvas: PKCanvasView = {
    let canvasView = PKCanvasView()
    let drawing = PKDrawing.init()
    canvasView.drawing = drawing;
    if #out there(iOS 14.0, *) {
      canvasView.drawingPolicy = .anyInput
    }
    canvasView.isOpaque = false;
    canvasView.backgroundColor = .clear;
    canvasView.isMultipleTouchEnabled = true;
    canvasView.backgroundColor = .yellow
    canvasView.instrument = PKInkingTool(.pen, coloration: UIColor.black, width: 5)
    canvasView.becomeFirstResponder()
    return canvasView;
  }()
}

Might somebody clarify the problem to me? Thanks!



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments