Utils
To use the functionality provided by the utils/utils
module, first require/import the module:
isFileOrResourcePath() function
Verify if the specified path
points to a resource or a local file. The function returns a boolean value of:
-
true
- if the path has a valid path structure -
false
- if the path is not a file path
isDataURI() function
Checks if the specified URI is a data URI.
- Returns
true
if the string is data URL, otherwisefalse
openUrl() function
Open an URL on device with the default browser
escapeRegexSymbols() function
Escapes special regex symbols (., *, ^, $, etc.) in string in order to create a valid regex from it.
convertString() function
Converts a string value to a number or boolean;
getDisplayDensity() function
Returns the display density of the device.
toDevicePixels() function
Converts value from device independent pixels to device pixels.
toDeviceIndependentPixels() function
Convert value to device independent pixels.
round() method
Rounds value used in layout.
If we set
123.56px
as a input the returned value will be124px
.
executeOnMainThread() method
The method checks if the current thread is the main thread. It will directly call the passed function if it is, or dispatches it to the main thread otherwise.
mainThreadify() method
The method returns a function wrapper which executes the supplied function on the main thread. The wrapper behaves like the original function and passes all of its arguments BUT discards its return value.
Platform specific methods
Android
getApplication() function
Returns an instance of native Android application The returned value will be of type android.app.Application
.
getApplicationContext() function
Returns the Android application context. The returned value will be of type android.content.Context
.
getInputMethodManager() function
Returns an instance of native Android input method manager. The returned value will be an
android.view.inputmethod.InputMethodManager
showSoftInput() function
Show keyboard for a specific element.
dismissSoftInput() function
Hides the soft input method, usually a soft keyboard.
stringArrayToStringSet() function
Converts a string array into a String hash set.
stringSetToStringArray() function
Converts a string hash set into array of strings
getDrawableId() function
Returns the drawable id from a given resource name
getStringId() function
Returns the id of the string from the resources, while using its name
getId() function
Returns the id from a resource, while passing string with resource type and name. eg: :drawable/<resource_name>
, :string/<resource_name>
getPalleteColor() function
Returns a color from the current theme using the resource color name.
iOS
jsArrayToNSArray() function
Converts a JavaScript array to a NSArray
nsArrayToJSArray() function
Converts a NSArray to a JavaScript array.
isLandscape() function
Returns true
if current orientation is Landscape.
MajorVersion() function
Returns a number
with the iOS device major version(eg 8.1 will return 8).
openFile() function
Opens file with associated application, while using file path.