Applying a class to a plugin


#1

Hello,

I installed this plugin: https://www.npmjs.com/package/nativescript-autocomplete

I am trying to apply a class to the element it creates in order to position it on the screen, but I cannot seem to target the element by class or id.

<ac:Autocomplete items="{{list}}" itemTap=“itemTapped”/>

Has anyone else worked with the plugin before


#2

The initial plugin design consumes android.R.layout.simple_list_item_1


#3

@triniwiz,

Can you elaborate a bit? I am still relatively new to NS/JS.

Thank You,

Randy


#4

I still have not had any luck getting a class added or being able to get it styled. Can anyone help?

Thank You,

Randy


#5

Hey @randy,

Since you’re still learning :slight_smile: just ignore @triniwiz :stuck_out_tongue_winking_eye:

This line in the plugin is key in learning how the plugin works mostly: https://github.com/triniwiz/nativescript-autocomplete/blob/master/autocomplete.android.ts#L7 You’ll see this plugins actual class (not css class) extends the nativescript core View class. Which the api docs for that core class are here: http://docs.nativescript.org/api-reference/classes/ui_core_view.view.html and you’ll see all of the properties and methods for the View class which the autocomplete extends so it should have access to those properties. This can depend on the way the class is written but it should work. Something you can try is to apply a style directly to the autocomplete with the style property or one of the style properties such as

xml

<ac:Autocomplete  items="{{list}}" itemTap="itemTapped" backgroundColor="red" color="#fff" />

If that works then you have a start for now styling the view component. If it doesn’t then the plugin source likely needs some tweaking. Also be aware some native android components don’t map directly to a CSS abstraction with the NS framework bc it’s not something easily done (hope that makes sense). One way to think of this a little better is if the native android widget doesn’t expose a public method to change something on the widget then NS doesn’t have a great way to write an abstraction and map it to a CSS property for us to simply use. Could go on for a while but hopefully this helps some :slight_smile:


#6

@bradwaynemartin, very helpful.

Thank You,

Randy