emadalam / atvjs

Blazing fast Apple TV application development using pure JavaScript
https://emadalam.github.io/atvjs
MIT License
311 stars 49 forks source link

How to handle Deep Linking from TopShelf when using MenuPages #48

Closed quochuy closed 5 years ago

quochuy commented 6 years ago

When using Menu Pages like the boilerplate, how can I handle deeplinking from the app Top Shelf? I'd like to check if the "options" parameter of onLaunch has the "DEEPLINK" property and load the movies page directly without loading the Home page.

quochuy commented 5 years ago

I've found the solution. In webpack.config.js, I've added libraryTarget and library properties to output:

    output = {
        path: __dirname,
        filename: '[name].js',
        libraryTarget: 'var',
        library: 'EntryPoint'
    };

This allows calling a JS function inside the app.js from the Swift file.

From AppDelegate.swift I then call context.evaluateScript("EntryPoint.deepLinkDiveIn('(URLString)')")

And inside the app.js

module.exports = {
  deepLinkDiveIn: function (url) {
    // Process the URL and call ATV.Navigation.navigate()
  }
}