Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/support for ios14 #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ios/RNMagicScript.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1030;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1210;
ORGANIZATIONNAME = MagicLeap;
TargetAttributes = {
44318E8E22CB4E0C0060575D = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
LastUpgradeVersion = "1210"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -42,8 +42,6 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -53,8 +51,8 @@
ReferencedContainer = "container:RNMagicScript.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -75,8 +73,6 @@
ReferencedContainer = "container:RNMagicScript.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
LastUpgradeVersion = "1210"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
LastUpgradeVersion = "1210"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -30,8 +30,6 @@
codeCoverageEnabled = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -52,8 +50,6 @@
ReferencedContainer = "container:RNMagicScript.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
11 changes: 10 additions & 1 deletion ios/RNMagicScript/bridge/ARView/RCTARView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
64 changes: 46 additions & 18 deletions ios/RNMagicScript/components/Utils/Extensions/UIFont+Lomino.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@ 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)
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
// Check Lomino font first
let name: String = UIFont.lominoFontName(from: style, weight: weight)
if let font = UIFont(name: name, size: size) {
return font
}

return font
}

public func with(traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
guard let descriptor = fontDescriptor.withSymbolicTraits(traits) else {
return self
// 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)!
}

return UIFont(descriptor: descriptor, size: 0)

// Then use system font
let systemFont: UIFont = UIFont.systemFont(ofSize: size, weight: UIFont.UIFontWeight(from: weight))
if style == .italic {
return systemFont.with(traits: .traitItalic)
}

return systemFont
}

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"
Expand All @@ -57,6 +57,23 @@ extension UIFont {
return (style == .normal) ? "LominoUIApp-ExtraBold" : "LominoUIApp-ExtraBoldItalic"
}
}

fileprivate static func avenirNextFontName(from style: FontStyle, weight: FontWeight) -> String {
switch weight {
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"
}
}

public static func UIFontWeight(from weight: FontWeight) -> UIFont.Weight {
switch weight {
Expand All @@ -75,3 +92,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)
}
}
37 changes: 33 additions & 4 deletions ios/RNMagicScriptHostApplication/sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class ViewController: UIViewController {
super.viewDidLoad()
setupScene()

// setupPrismWithModels()
// setupPrismForHitTest()
setupPrismForDialog()
// setupPrismWithModels()
// setupPrismForHitTest()
// setupPrismForDialog()
setupPrismForFontTest()

setupARView()
arView.register(self)
Expand Down Expand Up @@ -90,7 +91,6 @@ class ViewController: UIViewController {
NodesManager.instance.updateLayout()
}


fileprivate func setupPrismForHitTest() {
let prismId = "prism_hit_test"
let prism: Prism = Prism()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
16 changes: 12 additions & 4 deletions ios/RNMagicScriptTests/sources/specs/UiNodes/UiTextNodeSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand Down Expand Up @@ -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]])
Expand Down Expand Up @@ -324,4 +324,12 @@ class UiTextNodeSpec: QuickSpec {
}
}
}

private func is_iOS14() -> Bool {
if #available(iOS 14.0, *) {
return true
} else {
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down