Skip to content
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
148 changes: 47 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,105 +9,51 @@

# MagicScript Components ReactNative

## Prerequisites

### Create a project

The instruction assumes that you have the following tools installed and you have set environment variables properly:
- npm or yarn
- react-native-cli

**Steps:**

1. Create a new project:
`react-native init AwesomeProject --version 0.60.5`
2. Go to the project directory
3. Add Magic Script Components ReactNative library to the project:
`yarn add magic-script-components-react-native`
4. Add Magic Script Components library to the project:
`yarn add magic-script-components`
5. Execute `react-native link` in order to link the libraries,
6. In the main project directory add `proxy_mobile` folder from [https://github.com/magic-script/magic-script-components-catalog](https://github.com/magic-script/magic-script-components-catalog/tree/master/)


### Pre-configuration for Android

The instruction assumes that you have the following tools installed and you have set environment variables properly:
- npm or yarn
- react-native-cli
- Android Studio (or a standalone Android SDK)
- Java JDK

**Steps:**

1. In the `./android/build.gradle` file set `minSdkVersion` to 24
2. Open `android/app/src/main/AndroidManifest.xml` file and add the following **between** the `<application>` tags:


```
<meta-data
android:name="com.google.ar.core"
android:value="required" />
```

Add the permission to use the Camera:
`<uses-permission android:name="android.permission.CAMERA" />`

And optionally this **above** the `<application>` tag:
`<uses-feature
android:name="android.hardware.camera.ar"
android:required="true" />`

*This tag indicates that this application requires ARCore. This results in the application
only being visible in the Google Play Store on devices that support ARCore)

You can compare your AndroidManifest file with [this one](https://github.com/magic-script/magic-script-components-catalog/blob/master/android/app/src/main/AndroidManifest.xml)

### Pre-configuration for iOS

The instruction assumes that you have the following tools installed and you have set environment variables properly:
- npm or yarn
- react-native-cli
- XCode version > 10
- CocoaPods version > 1.7.5

1. Create Empty.swift file inside project and `Create bridging header file`
2. In Podfile file update `platform :ios, ‘9.0’` to `platform :ios, ‘12.0’`
3. Declare `Privacy - Camera Usage Description` in Info.plist
4. Declare `Privacy - Location When In Use Usage Description` in Info.plist
5. Open terminal, navigate to `./ios` directory and execute `pod install` in order to install necessary Pods

### General pre-configuration & project building

**Steps**
1. Run `yarn` or `npm install` to install the dependencies
2. Replace App.js content with the following:
```
import React from 'react';
import { View, Text } from 'magic-script-components';

class MyApp extends React.Component {
render() {
return (
<View>
<Text localPosition={[0, 0, 0]} alignment={'center-center'}>Welcome in AR!</Text>
</View>
);
}
}
export default MyApp

```
3. Replace `index.js` content with the following:
```
import React from 'react';
import { MagicScript } from './proxy_mobile';
import MyApp from './App';

MagicScript.registerApp('AwesomeProject', <MyApp />, false);

```
4. In order to build & install the application on Android or iOS device, execute one of the following in root directory:

`react-native run-android`
or
`react-native run-ios`
Make sure you have:

- properly set up an environment for **React Native** (see [React Native CLI Quickstart](https://reactnative.dev/docs/environment-setup) for iOS|Android),

- installed either [yarn](https://classic.yarnpkg.com/en/docs/install/) or [npm](https://www.npmjs.com/get-npm),

- installed [MagicScript Command Line Toolkit](https://github.com/magic-script/magic-script-cli):

```
npm install -g magic-script-cli
```

<p>&nbsp;</p>

## Create a react native project

To create a sample project, type the command below and follow instructions in the wizard.
```
magic-script init
````

Remember to select:
- **Components** app,
- **Landscape** app type,
- **iOS** or **Android** platform.

<img src="https://rawcdn.githack.com/magic-script/magic-script-components-react-native/2a12dbc27a9d3684ff24f4395a131da6d47ee071/docs/screens/mxs_wizard.gif" height="160">

## Build and run the project

1. Move to the root directory of the project

```
cd AwesomeProject
```

2. To build and run the project, type:
```
magic-script build ios
```
or
```
magic-script build android
```

This will build the app for the specified platform and will try to run in on a local emulator.
4 changes: 3 additions & 1 deletion ios/RNMagicScript.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1030;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1210;
ORGANIZATIONNAME = MagicLeap;
TargetAttributes = {
44318E8E22CB4E0C0060575D = {
Expand Down Expand Up @@ -3068,6 +3068,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 @@ -3127,6 +3128,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)
}
}
Loading