scalajs-react-interface / discuss

Community forum for SRI
Apache License 2.0
0 stars 0 forks source link

CRNA Templates #1

Closed chandu0101 closed 6 years ago

chandu0101 commented 7 years ago

Ideas :

1) Export root component to toplevel using JSExportTopLevel and then use it in App.js

Scala.JS Code :

package object components {
 @JSExportTopLevel("scalajs_root_component")
  val root = StackNavigator(
    registerStackScreen[HomeScreen](navigationOptions = NavigationStackScreenOptions(title = "Scala.js Home"))
  )
}

App.js

import React from 'react';
import * as sjs from './assets/scalajs-output-android.js';

export default class App extends React.Component {
  render() {
      console.log(sjs);
      console.log(sjs.scalajs_root_component);
      return (
      React.createElement(sjs.scalajs_root_component,{})
    );
  }
}

Result:

sjs.scalajs_root_component returning null! (Investigate more...)

chandu0101 commented 7 years ago

lazy initialization FTW! ;) , make root def and it works :)

chandu0101 commented 7 years ago

TODO: find a way to to pass custom transformer --transformer scalajsTransformer

weihsiu commented 7 years ago

Great! Thanks for the investigative work!

chandu0101 commented 7 years ago

to pass custom transformer , add following to app.json

"packagerOpts": {
  "transformer": "scalajsTransformer"
}

Source: https://forums.expo.io/t/how-to-pass-custom-transformer-to-react-native-scripts/1159

frgomes commented 7 years ago

It should be

"packagerOpts": {
  "transformer": "scalajsTransformer.js"
}

... but

$ exp --start --android --dev

complains like this:

[exp] Cannot find module 'metro-bundler/build/transformer'
chandu0101 commented 7 years ago

@frgomes try loading original transformer from src folder instead of build .

frgomes commented 7 years ago

SOLVED

Instructions here: https://github.com/frgomes/mobile.g8/tree/expo-support

chandu0101 commented 7 years ago

@frgomes 👍 👏

virtualirfan commented 6 years ago

Looks to me like this issue can be closed. Please yell if I missed something.