Skip to content
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

Using external jsx instead of inline one #79

Closed
varadig opened this issue Sep 29, 2017 · 2 comments
Closed

Using external jsx instead of inline one #79

varadig opened this issue Sep 29, 2017 · 2 comments

Comments

@varadig
Copy link

varadig commented Sep 29, 2017

I wanted to use external jsx for instead of inline, with compiletime macro:


class Main {
    public static function main() {
        AppRegistry.registerComponent('TestReactNative', function() return App);

    }
}
@:expose('App')
class App extends ReactComponent{
    function new(props) {

        super(props);

        state = {
            scene: 0
        }
    }


    override function render() {
        function goto(i) setState({scene: i});
        return switch state.scene {
            default:
                jsx(CompileTime.readFile("jsx/Home.jsx"));
        }
    }
}

Home.jsx:

<WebView
    source={{uri: 'https://github.com/facebook/react-native'}}
    style={{marginTop: 20}}
>

</WebView>

but I got this error when compile:

/usr/local/lib/haxe/std/haxe/macro/ExprTools.hx:289: characters 11-16 : Unsupported expression: { expr => ECall({ expr => EField({ expr => EConst(CIdent(CompileTime)), pos => #pos(src/Main.hx:35: characters 20-31) },interpolateFile), pos => #pos(src/Main.hx:35: characters 20-47) },[{ expr => EConst(CString(jsx/Home.jsx)), pos => #pos(src/Main.hx:35: characters 48-62) }]), pos => #pos(src/Main.hx:35: characters 20-63) }
/Volumes/Work/develop/hx/libs/react/git/src/lib/react/ReactMacro.hx:27: characters 19-43 : Called from
src/Main.hx:35: characters 16-64 : Called from

How can I use external jsx with RNhaxe, if I can?

thanks

@elsassph
Copy link
Contributor

elsassph commented Sep 29, 2017

It's a good idea, but the JSX macro runs before your readFile.

I encourage you to look into forking haxe-react and patching the JSX macro to support something native like:

    override function render() {
        function goto(i) setState({scene: i});
        return switch state.scene {
            default:
                jsx("./jsx/Home.jsx");
        }
    }

@elsassph
Copy link
Contributor

elsassph commented Oct 3, 2017

Duplicate of issue #1

@elsassph elsassph closed this as completed Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants