3

I am building a simple NativeScript app, and am trying to do it using a TypeScript base code.

I am using Sublime Text 3 under OSX.

I realized by looking at the demo apps that the tns_modules matches the NativeScript repository so I added it to my app/ folder as a Git submodule, and then compiled it (npm i && grunt). Is that the wrong way to integrate these modules?

I then realized that I could not just run a tns emulate android of my app made of .ts files: I had to compile them too. So I set up a Grunt task to do so, but it was not easy to handle the dependencies. I ended up with this Gruntfile.coffee in app/:

module.exports = (grunt) ->
    grunt.loadNpmTasks 'grunt-typescript'

    grunt.config 'typescript',
        build:
            src: [
                '**/*.ts'
                '!*_modules/**'
            ]
            options:
                references: [
                    'tns_modules/bin/dist/definitions/**/*.d.ts'
                ]
                target: 'es5'
                sourceMap: false
                declaration: false
                module: 'commonjs'
                noResolve: true

And it works with simple code, e.g. I'm able to extend a module like Observable by writing:

import observable = require("data/observable");
class Activities extends observable.Observable {
    //...
}

I then compile with grunt (the .js files are created along with the .ts ones) and run with tns emulate android (with Genymotion emulator).

Is it the right architecture for my development? When I use Telerik Platform, the compilation process is hidden so I'm not sure I'm doing it right.

And now I'm trying to use Telerik's side-bar module directly in a page's XML file, the way they do it:

<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded" xmlns:tsb="./tns_modules/bin/dist/apps/TelerikNEXT/TelerikUI/side-bar">
    <tsb:SideBar title="MyApp">
        ...

But I get this error:

E/TNS.Native( 2456): TypeError: Cannot read property 'android' of undefined E/TNS.Native( 2456): File: "/data/data/org.nativescript.scmobile/files/app/./tns_modules/bin/dist/apps/TelerikNEXT/TelerikUI/side-bar, line: 39, column: 39

Which corresponds to:

this._android = new com.telerik.android.primitives.widget.sidedrawer.RadSideDrawer(this._context);

Any idea how I should include these modules? Note that I'm new to mobile dev.

1 Answer 1

1

The sidebar, which they're using in the example, is a (payed) controller from Telerik.

As such, it needs to be downloaded and added with tns library add {ios|android} /path/to/the/sidebar.

This command will read project.properties file from the specified shared library folder and will add a reference to it in your project. If in turn the shared library has references to other projects then these projects will be included recursively. As a result, this will create a new folder lib which is sibling to already existing app and platforms.

Sign up to request clarification or add additional context in comments.

3 Comments

I see, but these controls are not free ($500!) and not present in the trial... so I guess I have to make my own?!
Unfortunately, pretty much so. Or find another component.
@antoine129 take a look at the animated side menu module that I created. It's not updated for the latest version of NativeScript yet, but it could give you a head start on building your own. http://nuvious.com/Blog/2015/5/30/its-finally-here-nativescript-animated-side-menu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.