From af5a6a65783782e0ec1e1d8ab989496dd333b96a Mon Sep 17 00:00:00 2001 From: Pawel Leszkiewicz Date: Thu, 22 Oct 2020 10:53:48 +0200 Subject: [PATCH 1/8] Changes that let the app to run on simulator. --- ios/RNMagicScript/bridge/ARView/RCTARView.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ios/RNMagicScript/bridge/ARView/RCTARView.swift b/ios/RNMagicScript/bridge/ARView/RCTARView.swift index 9edbc0e2..90b454ce 100644 --- a/ios/RNMagicScript/bridge/ARView/RCTARView.swift +++ b/ios/RNMagicScript/bridge/ARView/RCTARView.swift @@ -124,7 +124,16 @@ import SceneKit } fileprivate func createARView() -> ARSCNView { - let view = ARSCNView() + + var options: [String : Any] = [:] + #if targetEnvironment(simulator) + options[SCNView.Option.preferredRenderingAPI.rawValue] = NSNumber(value: SCNRenderingAPI.openGLES2.rawValue) + #endif + + let view = ARSCNView(frame: CGRect.zero, options: options) + #if targetEnvironment(simulator) + view.scene = SCNScene() + #endif view.autoenablesDefaultLighting = true view.automaticallyUpdatesLighting = true view.backgroundColor = UIColor(white: 55.0 / 255.0, alpha: 1.0) From 3974e9fbe45cb37b759cbdc285e2772402ec0adc Mon Sep 17 00:00:00 2001 From: Pawel Leszkiewicz Date: Thu, 22 Oct 2020 10:54:16 +0200 Subject: [PATCH 2/8] Fix issue with system font on iOS 14. --- .../Utils/Extensions/UIFont+Lomino.swift | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift b/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift index 0dbb7b1e..fee11686 100644 --- a/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift +++ b/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift @@ -20,17 +20,19 @@ extension UIFont { public static func font(with style: FontStyle, weight: FontWeight, size: CGFloat) -> UIFont { let name: String = UIFont.fontName(from: style, weight: weight) - guard let font = UIFont(name: name, size: size) else { - // return system font in case Lomino font not installed - let systemFont = UIFont.systemFont(ofSize: size, weight: UIFont.UIFontWeight(from: weight)) - if style == .italic { - return systemFont.with(traits: .traitItalic) - } - - return systemFont + if let font = UIFont(name: name, size: size) { + return font } - return font + let systemFontName: String = UIFont.systemFontName(from: style, weight: weight) + print("systemFontName: \(systemFontName)") + let systemFont: UIFont = UIFont(name: systemFontName, size: size) ?? UIFont.systemFont(ofSize: 20.0, weight: UIFont.UIFontWeight(from: weight)) + + if style == .italic { + return systemFont.with(traits: .traitItalic) + } + + return systemFont } public func with(traits: UIFontDescriptor.SymbolicTraits) -> UIFont { @@ -57,6 +59,37 @@ extension UIFont { return (style == .normal) ? "LominoUIApp-ExtraBold" : "LominoUIApp-ExtraBoldItalic" } } + + fileprivate static func systemFontName(from style: FontStyle, weight: FontWeight) -> String { + var name: String + if #available(iOS 14.0, *) { + name = "HelveticaNeue"//.SFUIText" + } else { + name = "HelveticaNeue" + } + + let fontWeight = UIFontWeight(from: weight) + if let weightName = UIFont.name(of: fontWeight) { + name += "-" + weightName + } + + return name + } + + fileprivate static func name(of weight: UIFont.Weight) -> String? { + switch weight { + case .ultraLight: return "UltraLight" + case .thin: return "Thin" + case .light: return "Light" + case .regular: return nil + case .medium: return "Medium" + case .semibold: return "Semibold" + case .bold: return "Bold" + case .heavy: return "Heavy" + case .black: return "Black" + default: return nil + } + } public static func UIFontWeight(from weight: FontWeight) -> UIFont.Weight { switch weight { From 12e078905fa8680013274b5dbb08afd35a9c96cb Mon Sep 17 00:00:00 2001 From: Pawel Leszkiewicz Date: Thu, 22 Oct 2020 10:55:55 +0200 Subject: [PATCH 3/8] Prevent the prism's title from updating continuously. --- .../components/BaseNodes/Prism/PrismContextMenu.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ios/RNMagicScript/components/BaseNodes/Prism/PrismContextMenu.swift b/ios/RNMagicScript/components/BaseNodes/Prism/PrismContextMenu.swift index 251b713c..063055e3 100644 --- a/ios/RNMagicScript/components/BaseNodes/Prism/PrismContextMenu.swift +++ b/ios/RNMagicScript/components/BaseNodes/Prism/PrismContextMenu.swift @@ -28,10 +28,12 @@ struct PrismContextMenuBuilder { class PrismContextMenu: UiNode { var text: String = "" { didSet { - titleNode.text = text - titleNode.layoutIfNeeded() - setNeedsLayout() - updateLayout() + if titleNode.text != text { + titleNode.text = text + titleNode.layoutIfNeeded() + setNeedsLayout() + updateLayout() + } } } From 2088a014bd491b1e634716d7087eed2c05ed45b6 Mon Sep 17 00:00:00 2001 From: Pawel Leszkiewicz Date: Thu, 22 Oct 2020 10:56:31 +0200 Subject: [PATCH 4/8] Update syntax in unit tests. --- .../sources/specs/Utils/Maths/PlaneSpec.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNMagicScriptTests/sources/specs/Utils/Maths/PlaneSpec.swift b/ios/RNMagicScriptTests/sources/specs/Utils/Maths/PlaneSpec.swift index 06fbafb5..7c75f8e5 100644 --- a/ios/RNMagicScriptTests/sources/specs/Utils/Maths/PlaneSpec.swift +++ b/ios/RNMagicScriptTests/sources/specs/Utils/Maths/PlaneSpec.swift @@ -58,7 +58,7 @@ class PlaneSpec: QuickSpec { it("should invoke assert for wrong vec4") { let referenceVector = SCNVector4(0, 0, 0, 2.0) - expect { _ = Plane(vector: referenceVector) }.to(throwAssertion()) + expect(_ = Plane(vector: referenceVector)).to(throwAssertion()) } } From 56ffe62f30728f0981c12e6b02c8746e43adc076 Mon Sep 17 00:00:00 2001 From: Pawel Leszkiewicz Date: Mon, 26 Oct 2020 14:43:23 +0100 Subject: [PATCH 5/8] Updates of projects settings. --- ios/RNMagicScript.xcodeproj/project.pbxproj | 4 +++- .../xcshareddata/xcschemes/RNMagicScript.xcscheme | 10 +++------- .../xcschemes/RNMagicScriptHostApplication.xcscheme | 2 +- .../xcschemes/RNMagicScriptResources.xcscheme | 6 +----- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/ios/RNMagicScript.xcodeproj/project.pbxproj b/ios/RNMagicScript.xcodeproj/project.pbxproj index 4869267d..d4832f74 100644 --- a/ios/RNMagicScript.xcodeproj/project.pbxproj +++ b/ios/RNMagicScript.xcodeproj/project.pbxproj @@ -2037,7 +2037,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1030; - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1210; ORGANIZATIONNAME = MagicLeap; TargetAttributes = { 44318E8E22CB4E0C0060575D = { @@ -3052,6 +3052,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -3111,6 +3112,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; diff --git a/ios/RNMagicScript.xcodeproj/xcshareddata/xcschemes/RNMagicScript.xcscheme b/ios/RNMagicScript.xcodeproj/xcshareddata/xcschemes/RNMagicScript.xcscheme index 39fdc2a7..994e3c0c 100644 --- a/ios/RNMagicScript.xcodeproj/xcshareddata/xcschemes/RNMagicScript.xcscheme +++ b/ios/RNMagicScript.xcodeproj/xcshareddata/xcschemes/RNMagicScript.xcscheme @@ -1,6 +1,6 @@ - - - - + + - - - - - - Date: Mon, 26 Oct 2020 14:45:19 +0100 Subject: [PATCH 6/8] Use AvenirNext font on iOS 14. Update unit tests. --- .../Utils/Extensions/UIFont+Lomino.swift | 73 +++++++++---------- .../UiNodes/Group/GroupContainerSpec.swift | 2 +- .../specs/UiNodes/UiTextNodeSpec.swift | 16 +++- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift b/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift index fee11686..191c17bd 100644 --- a/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift +++ b/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift @@ -19,15 +19,19 @@ import UIKit extension UIFont { public static func font(with style: FontStyle, weight: FontWeight, size: CGFloat) -> UIFont { - let name: String = UIFont.fontName(from: style, weight: weight) + // Check Lomino font first + let name: String = UIFont.lominoFontName(from: style, weight: weight) if let font = UIFont(name: name, size: size) { return font } - let systemFontName: String = UIFont.systemFontName(from: style, weight: weight) - print("systemFontName: \(systemFontName)") - let systemFont: UIFont = UIFont(name: systemFontName, size: size) ?? UIFont.systemFont(ofSize: 20.0, weight: UIFont.UIFontWeight(from: weight)) + if #available(iOS 14.0, *) { + let systemFontName: String = UIFont.avenirNextFontName(from: style, weight: weight) + return UIFont(name: systemFontName, size: size)! + } + // Then use system font + let systemFont: UIFont = UIFont.systemFont(ofSize: size, weight: UIFont.UIFontWeight(from: weight)) if style == .italic { return systemFont.with(traits: .traitItalic) } @@ -35,15 +39,7 @@ extension UIFont { return systemFont } - public func with(traits: UIFontDescriptor.SymbolicTraits) -> UIFont { - guard let descriptor = fontDescriptor.withSymbolicTraits(traits) else { - return self - } - - return UIFont(descriptor: descriptor, size: 0) - } - - fileprivate static func fontName(from style: FontStyle, weight: FontWeight) -> String { + fileprivate static func lominoFontName(from style: FontStyle, weight: FontWeight) -> String { switch weight { case .extraLight: return (style == .normal) ? "LominoUIApp-Light" : "LominoUIApp-LightItalic" @@ -60,34 +56,20 @@ extension UIFont { } } - fileprivate static func systemFontName(from style: FontStyle, weight: FontWeight) -> String { - var name: String - if #available(iOS 14.0, *) { - name = "HelveticaNeue"//.SFUIText" - } else { - name = "HelveticaNeue" - } - - let fontWeight = UIFontWeight(from: weight) - if let weightName = UIFont.name(of: fontWeight) { - name += "-" + weightName - } - - return name - } - - fileprivate static func name(of weight: UIFont.Weight) -> String? { + fileprivate static func avenirNextFontName(from style: FontStyle, weight: FontWeight) -> String { switch weight { - case .ultraLight: return "UltraLight" - case .thin: return "Thin" - case .light: return "Light" - case .regular: return nil - case .medium: return "Medium" - case .semibold: return "Semibold" - case .bold: return "Bold" - case .heavy: return "Heavy" - case .black: return "Black" - default: return nil + case .extraLight: + return (style == .normal) ? "AvenirNext-UltraLight" : "AvenirNext-UltraLightItalic" + case .light: + return (style == .normal) ? "AvenirNext-UltraLight" : "AvenirNext-UltraLightItalic" + case .regular: + return (style == .normal) ? "AvenirNext-Regular" : "AvenirNext-Italic" + case .medium: + return (style == .normal) ? "AvenirNext-Medium" : "AvenirNext-MediumItalic" + case .bold: + return (style == .normal) ? "AvenirNext-Bold" : "AvenirNext-BoldItalic" + case .extraBold: + return (style == .normal) ? "AvenirNext-Heavy" : "AvenirNext-HeavyItalic" } } @@ -108,3 +90,14 @@ extension UIFont { } } } + +// MARK: - Traits +extension UIFont { + public func with(traits: UIFontDescriptor.SymbolicTraits) -> UIFont { + guard let descriptor = fontDescriptor.withSymbolicTraits(traits) else { + return self + } + + return UIFont(descriptor: descriptor, size: 0) + } +} diff --git a/ios/RNMagicScriptTests/sources/specs/UiNodes/Group/GroupContainerSpec.swift b/ios/RNMagicScriptTests/sources/specs/UiNodes/Group/GroupContainerSpec.swift index f146cdfe..ecb7457d 100644 --- a/ios/RNMagicScriptTests/sources/specs/UiNodes/Group/GroupContainerSpec.swift +++ b/ios/RNMagicScriptTests/sources/specs/UiNodes/Group/GroupContainerSpec.swift @@ -116,7 +116,7 @@ class GroupContainerSpec: QuickSpec { let items = self.prepareSampleTransformNodes() items.forEach { group.addItem($0) } let targetBounds = CGRect(x: 0.3, y: -0.5, width: 2.63, height: 1.45) - expect(group.getBounds()).to(beCloseTo(targetBounds)) + expect(group.getBounds()).to(beCloseTo(targetBounds, epsilon: 0.002)) } it("should return size") { diff --git a/ios/RNMagicScriptTests/sources/specs/UiNodes/UiTextNodeSpec.swift b/ios/RNMagicScriptTests/sources/specs/UiNodes/UiTextNodeSpec.swift index 0c95cc0c..4efdbf4b 100644 --- a/ios/RNMagicScriptTests/sources/specs/UiNodes/UiTextNodeSpec.swift +++ b/ios/RNMagicScriptTests/sources/specs/UiNodes/UiTextNodeSpec.swift @@ -246,8 +246,8 @@ class UiTextNodeSpec: QuickSpec { context("when wrap disabled") { let referenceBoundsSize = CGSize.zero - let shortTextRefereneceSizeForBounds = CGSize(width: 0.0426, height: 0.0144) - let veryLongTextRefereneceSizeForBounds = CGSize(width: 0.4986, height: 0.0144) + let shortTextRefereneceSizeForBounds: CGSize = is_iOS14() ? CGSize(width: 0.0444, height: 0.0168) : CGSize(width: 0.0426, height: 0.0144) + let veryLongTextRefereneceSizeForBounds: CGSize = is_iOS14() ? CGSize(width: 0.5202, height: 0.0168) : CGSize(width: 0.4986, height: 0.0144) it("should change bounds when text length increases") { node.update(["boundsSize" : ["wrap": false]]) @@ -290,8 +290,8 @@ class UiTextNodeSpec: QuickSpec { context("when boundsSize.height not set") { let referenceBoundsSize = CGSize(width: 0.1, height: 0) - let refereneceBoundsSizeWhenWrapDisabled = CGSize(width: 0.1, height: 0.0144) - let refereneceBoundsSizeWhenWrapEnabled = CGSize(width: 0.1, height: 0.072) + let refereneceBoundsSizeWhenWrapDisabled = is_iOS14() ? CGSize(width: 0.1, height: 0.0168) : CGSize(width: 0.1, height: 0.0144) + let refereneceBoundsSizeWhenWrapEnabled = is_iOS14() ? CGSize(width: 0.1, height: 0.1152) : CGSize(width: 0.1, height: 0.072) it("should change bounds when wrap changes") { node.update(["boundsSize" : ["boundsSize": referenceBoundsSize.toArrayOfFloat, "wrap": false]]) @@ -324,4 +324,12 @@ class UiTextNodeSpec: QuickSpec { } } } + + private func is_iOS14() -> Bool { + if #available(iOS 14.0, *) { + return true + } else { + return false + } + } } From a61cc08b45c2286693b40c45705524f8355d62d0 Mon Sep 17 00:00:00 2001 From: Pawel Leszkiewicz Date: Mon, 26 Oct 2020 14:46:12 +0100 Subject: [PATCH 7/8] Test scene for fonts. --- .../sources/ViewController.swift | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/ios/RNMagicScriptHostApplication/sources/ViewController.swift b/ios/RNMagicScriptHostApplication/sources/ViewController.swift index 148899ca..ed2f3751 100644 --- a/ios/RNMagicScriptHostApplication/sources/ViewController.swift +++ b/ios/RNMagicScriptHostApplication/sources/ViewController.swift @@ -34,9 +34,10 @@ class ViewController: UIViewController { super.viewDidLoad() setupScene() - // setupPrismWithModels() - // setupPrismForHitTest() - setupPrismForDialog() +// setupPrismWithModels() +// setupPrismForHitTest() +// setupPrismForDialog() + setupPrismForFontTest() setupARView() arView.register(self) @@ -90,7 +91,6 @@ class ViewController: UIViewController { NodesManager.instance.updateLayout() } - fileprivate func setupPrismForHitTest() { let prismId = "prism_hit_test" let prism: Prism = Prism() @@ -219,6 +219,35 @@ class ViewController: UIViewController { NodesManager.instance.updateLayout() } + fileprivate func setupPrismForFontTest() { + let prismId = "prism_hit_test" + let prism: Prism = Prism() + prism.size = SCNVector3(1.0, 1.0, 1.0) + prism.debug = true + + NodesManager.instance.registerPrism(prism, prismId: prismId) + NodesManager.instance.addNode(prismId, toParent: sceneId) + + let styles: [FontStyle] = [.normal, .italic] + let weights: [FontWeight] = [.extraLight, .light, .regular, .medium, .bold, .extraBold] + + for style in styles { + let y: Float = (style == .normal) ? 0.3 : -0.1 + for (index, weight) in weights.enumerated() { + let text : UiTextNode = createComponent([ + "text": "\(weight.rawValue): abcdefghijklmnopqrstuwvxyz", + "textSize": 0.04, + "localPosition": [-0.3, y - Float(index) * 0.05, 0], + ], nodeId: "text_\(weight.rawValue)", parentId: prismId) + text.style = style + text.weight = weight + text.updateLayout() + } + } + + NodesManager.instance.updateLayout() + } + fileprivate func loadModel(_ filePath: String, index: Int, parentId: String) { let columns: Int = 2 let x: CGFloat = -0.3 + CGFloat(index % columns) * 0.3 From d155d97a0785d9162bc5f5b18f26c1517ba2f619 Mon Sep 17 00:00:00 2001 From: Pawel Leszkiewicz Date: Mon, 26 Oct 2020 14:54:43 +0100 Subject: [PATCH 8/8] Add explanation comment --- .../components/Utils/Extensions/UIFont+Lomino.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift b/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift index 191c17bd..48b0cd60 100644 --- a/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift +++ b/ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift @@ -25,6 +25,8 @@ extension UIFont { return font } + // Perform extra check for iOS 14 as there is an issue with system font + // (more info: https://stackoverflow.com/questions/64448087/missing-characters-in-scntext-ios-14) if #available(iOS 14.0, *) { let systemFontName: String = UIFont.avenirNextFontName(from: style, weight: weight) return UIFont(name: systemFontName, size: size)!