Lukas Anda
09/12/2023, 9:40 PM[SwiftUI] Accessing Environment<CGFloat>'s value outside of being installed on a View. This will always read the default value and will not update.
This is my implementation of the view:
struct TestView: View {
var body: some View {
VStack(alignment: .leading) {
LaTeX("The quadratic formula is $$x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}$$ and it has zeros at the roots of $f(x)=ax^2+bx+c$.")
.blockMode(.alwaysInline) // This method call actually causes the error because it modifies the environment variable of LaTeX
.font(.system(size: 16))
.frame(maxWidth:.infinity, alignment: .leading)
.background(.green)
}
.frame(alignment: .leading)
.frame(maxWidth: .infinity)
.background(.red)
}
}
class TestViewInterfaceImpl: TestViewInterface {
private var textView: UITextView?
func getView() -> UIView {
let controller = UIHostingController(rootView: TestView())
let targetSize = controller.sizeThatFits(in: CGSize(width: UIScreen.main.bounds.width, height:UIScreen.main.bounds.height))
controller.view.frame = CGRect(origin: .zero, size: CGSize(width: UIScreen.main.bounds.width, height:targetSize.height))
let view = UIView(frame: CGRect(origin: .zero, size: CGSize(width: UIScreen.main.bounds.width, height:targetSize.height)))
view.addSubview(controller.view)
return view
}
func showText(text: String) {
}
}
Ivan Matkov
09/13/2023, 6:57 AMLukas Anda
09/13/2023, 6:58 AM