Skip to content

Note : Materialize JSNI conversion to JSInterop

kevzlou7979 edited this page Jun 26, 2016 · 8 revisions

Don't use static methods (Except if your using Namespaces like Toast component)

If you use static context to your method you will get ```(TypeError) : Cannot read property 'material' of undefined ```

Javascript ```javascript $(".mydropdown").dropdown(); ``` JSInterop ```java @JsMethod public native JsMaterialElement dropdown(); ```

With Namespace

Javascript

Materialize.toast("message", 3000, funct);

JSInterop

JsMaterialElement.toast(msg, lifeMillis, className, () -> {
    if(callback != null) {
        callback.run();
    }
});

Defining Functions

Javascript

function({
  // some methods
});

JSInterop

new Functions.Func() {
   // Some methods
};

With JQuery selector to perform Materialize api

Javascript

$(".collapsible").collapsible();

JSInterop/b>

$(".collapsible").collapsible();

With JS Configuration Object

Javascript

options = {
  container: "body",
  selectYears: true,
  selectMonths: true,
  format: "yyyy/mm/dd";
};

JSInterop

@JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
public class JsDatePickerOptions {

    @JsProperty
    public String container;

    @JsProperty
    public boolean selectYears;

    @JsProperty
    public boolean selectMonths;

    @JsProperty
    public String format;

}