0

I'm very new to NativeScript. I chose it compared to React Native because I wanted 100% access to native API. I started playing with native plugins and read some tutorials like this one native libraries Now I'm trying to follow the same principle with this plugin FloatingActionButton

var app = require("application");
var platformModule = require("platform");
var fs = require("file-system");
var imageSource = require("image-source");

function creatingFab(args) {

    var fabMenu = new com.github.clans.fab.FloatingActionMenu(app.android.foregroundActivity);
    var fabButton = new com.github.clans.fab.FloatingActionButton(args.object.android);
    fabButton.setButtonSize(FloatingActionButton.SIZE_MINI);
    fabButton.setLabelText("Hello Button");
       
    //fabButton.setImageResource(imageSource.fromResource("logo"));
  
    fabMenu.addMenuButton(fabButton);
    fabMenu.hideMenuButton(false);
    
}

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo" class="page">
  
    <Page.actionBar>
        <ActionBar title="My App" icon="" class="action-bar">
        </ActionBar>
    </Page.actionBar>
   
    <StackLayout class="p-20">
        <Label text="Tap the button" class="h1 text-center"/>
        <Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-active"/>
        <Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
    </StackLayout>
    <android>
        <placeholder id="fab" tap="fabClick" class="fab-button" margin="15" creatingView="creatingFab"/>
   </android>
</Page>

error in emulator

Thank you in advance for your help

Selom
  • 392
  • 4
  • 14
  • cool stuff - if you want to use something already written using the android native FAB widget there is this plugin https://github.com/bradmartin/nativescript-floatingactionbutton but I understand the learning approach you're taking. It's where I started when I wrote that article over a year ago :) so keep doing what you're doing and you'll appreciate nativescript more and more. @MarekMaszay answer below might help. If not, the android lib you're using might require you pass an image which it looks like you commented out the line setting the image. – Brad Martin Mar 05 '17 at 21:16
  • 1
    @BradMartin, I'm a huge fan of your blog. Thanks to guys like you, this is only my second day of nativescript but I have learnt a lot. I will definitely use you plugin github.com/bradmartin/nativescript-floatingactionbutton . I have looked into it already. I was just trying to see If I could hook into any native plugin easily. I'm really amazed at what can be done with NativeScript. I just need to push it to the limit to see how far I can go with it :). – Selom Mar 05 '17 at 21:56
  • 1
    I have uncommented the line and followed @MarekMaszay advice but still not working. I will continue looking into it. – Selom Mar 05 '17 at 21:57
  • Thanks :) feel free to reach out on the forums https://discourse.nativescript.org/ and join the slack channel. Many great devs there that can help with any issue you encounter. – Brad Martin Mar 05 '17 at 21:58
  • @BradMartin I have joined the slack channel. Thanks – Selom Mar 05 '17 at 22:19

1 Answers1

1

try is as this based on this http://docs.nativescript.org/api-reference/classes/application.androidapplication.html#foregroundactivity

var fabMenu = new com.github.clans.fab.FloatingActionMenu(app.AndroidApplication.foregroundActivity);
Marek Maszay
  • 1,537
  • 1
  • 9
  • 11
  • I have tried this but I still have the same error. I will continue looking into the docs and the library code to see how to properly initialize it. – Selom Mar 05 '17 at 21:49