DEV Community

Oarabile Koore
Oarabile Koore

Posted on

Keeping It a Hundo on coding DroidScript Apps.

If you don't know DroidScript, ill give you a pint of knowledge:

Its basically a js framework that allows you to build android apps, a line of code
app.CreateButton(), adds a real android button. However if you don't want the hassle of learning, use HTML.
More benefits are NodeJS, ESM, Python(Via Brython) are available.

Even though I am not a day 1, I've gained immense knowledge about the framework. I am currently building a ui library - Material3, hopefully you can trust me broski 🫠.


Firstly :: Optimization On Code And App Speed

A normal ds app uses chrome's v8 which really isn't a problem, if you are to use a lot of app. methods, use ::

_Boost(true)
Enter fullscreen mode Exit fullscreen mode

This feature uses a faster java bridge interface, it is not documented but has been offered to use, this may mean it may have unknown issues, since it isn't heavily used and is experimental, i advise you don't.

Another solution is using

cfg.Fast
Enter fullscreen mode Exit fullscreen mode

The difference is cfg.Fast removes DOM features and uses the j2v8 JavaScript runtime.
J2V8 doesn't support the latest JavaScript Features, examples I've ran across are::

Object.values()
Object.is()
Object.has()
// I actually feel like its most of the Object Methods.
Enter fullscreen mode Exit fullscreen mode

The official known issues are setTimeout() and setInterval() so as fetch however a polyfill is available use app.Animate()
and the app.HttpRequest().

Another solution is using

cfg.Node
Enter fullscreen mode Exit fullscreen mode

Drawbacks are you cannot use app.Script or app.Include, you will have to use the node require method.

Another solution is using the

Obj.Batch()
Enter fullscreen mode Exit fullscreen mode

method on your components, that calls all your effects to the component at once.

Now more less of a solution is don't use a lot of app. methods at the start of the program, if necessary use app.Wait() with a complementary splash screen.


Secondly :: Writing Your Own Ui

I learnt this a few days ago, there is a reason for debug log.
If you want to implement a text edit refer to ds:: console messages and you will get an idea.
If i had knew i would have done the library quicker.

App.CreateLayout( LinearVCenter,FillXY )
-> #0
Lay.SetBackColor( #f5f5f5 )
App.CreateLayout( Absolute )
-> #1
Obj.SetSize( 0.8, null, )
App.CreateButton( null, null, Custom,NoSound )
-> #2
Obj.SetSize( 288, 65, dp )
Btn.SetStyle( #00000000, #00000000, 4, #bdbdbd, 2, 0 )
Obj.SetPosition( 0, 0.007853403141361256, , , )
Lay.AddChild( #2, )
App.CreateText( Username, , )
-> #3
Txt.SetFontFile( /Sys/fonts/mui/Regular.ttf )
Txt.SetTextColor( #009688 )
Txt.SetTextSize( 12, )
Obj.SetPadding( 4, 0, 4, 0, dp )
Obj.SetBackColor( #f5f5f5 )
Obj.SetPosition( 0.048, 0, , , )
Obj.SetVisibility( Hide )
Enter fullscreen mode Exit fullscreen mode

That could be well transcribed.


Thirdly :: Issues with callback optimizations

To avoid a
StackOverFlow/Memory Exceeded/CallStack Exceeded,
use I() and M(), the DroidScript Engine does callback optimizations by just caching the functions body.

DroidScript checks if a callback function already exists and uses it instead of creating a new instance.
This can cause issues when referring to other local variables in private scopes.
Therefore you can wrap your callback functions in an I() clause to force DroidScript to create a new callback instance for that scope.

I(cb.bind(obj))
//is the same as 
M(obj, cb)

// M() just uses a this context.
Enter fullscreen mode Exit fullscreen mode

I experienced this issue while porting Naterial3, its more likely to occur with codebases where objects have recurring methods and function calls.


Fourthly :: A Vision For A WORA Future

DroidScript isn't just an android framework, the Hybrid App Type is in beta, basically is a masked react without writing react code, to keep the ds Syntax the Hybrid App Type will be easier to adopt and hopefully allow porting to other OS's.

I really thought that Dave (DroidScript Inventor) would use, SmartScript.

Basically SmartScript is another framework Dave worked on 2013-2015(Estimated).
It carries the same DroidScript Syntax but allows you to write Windows Application using COM, which is outdated these days.

SmartScript allow use of real Os ui instead of emulation (HTML & Css).
It may have been easier to port to MAC and IOS Ecosystem, basing on what it was written with, i estimate Java.

The plan is to use Electron, silently i suggest Tauri,
even though i fell in love with the DroidScript Engine and wished if ported it would remain the same, no Electron or Tauri as id have to learn new api's.

The Hybrid app type has been promised for so long its hype is dying down, since 2017 and the structure looks like its been changed.

refer to : First Insight On Hybrid App Type

refer to code below: 2021 - Second Insight And Code Preview

//Configure for Hybrid app.
cfg.Hybrid

//Called after application is started.
function onStart()
{
    mainLay = ui.addLayout(null, "linear")

    apb = ui.addAppBar(mainLay, "My App", "menu", 1)
    apb.setOnMenu(openDrawer)

    apbLay = ui.addLayout(null, "Linear", "Horizontal,Right,NoDom,VCenter")
    apbTextField = ui.addTextField(apbLay, "", "outlined,secondary,small", 0.2)
    apbTextField.setPlaceholder('Search something...')
    apbBadge = ui.addButton(apbLay, "notifications", "icon")
    apbBadge.setTextColor('#ffffff')
    apbBadge.setBadge(9, 'primary')
    apbBtn = ui.addButton(apbLay, "account_circle", "Icon")
    apbBtn.setTextColor('#ffffff')
    apbBtn = ui.addButton(apbLay, "more_vert", "Icon")
    apbBtn.setTextColor('#ffffff')
//More Code
}
Enter fullscreen mode Exit fullscreen mode

refer to code below: 2024 -Current Hybrid App Type

class Main extends App
{
    onStart()
    {
        // Creates a fullscreen linear layout with objects align Top and Center
        this.main = ui.addLayout("main", "Linear", "Top,Center", 1, 1)

        // Adds an appbar to the layout
        this.apb = ui.addAppBar(this.main, "My App", "", 1)

        // Adds a button control with margins 1/10 of the parent width.
        this.btn = ui.addButton(this.main, "Button")
        this.btn.margins = 0.1
    }
}

Enter fullscreen mode Exit fullscreen mode

However its currently on 0.28, and as promises of DroidScript v3 are around (currently on DroidScript v2.69b1), and the removal of Material 2 link on first documentation page to suggest an upgrade.

That is partially the reason i decided to add an up-to date version of Material Design, currently I'm on version 0.79-beta3.


Fifthly : Neutral Take On DroidScript

DroidScript for long has been marketed as a learning tool for newbies and a prototyping tool, that's a shot at your own leg.

With many Android Api's supported and an ecosystem of plugins available so as ability to write a plugins using Java to port what you need is a big understatement.
DroidScript can be used to build real apps, almost the level of apps like WhatsApp.

Also DroidScript allows you to write less, no more XML or verbose Java, just JavaScript.
Even though it would be hotter with TypeScript ....

please lobby Google to add TypeScript support in Chromium (●'β—‘'●).

Now the downsides, your app icons cannot use the new Materialized themes, obviously not good at making RPG titles, you can brute force your way through ThreeJS <3.

Note you can use pre existing game engine to build 2D games.

I am an open for and to dude, but DroidScript is an exception, even though i am paying to build an open source plugin lol.

I support its development, hopefully if it gets bought by some large cooperation for a good name and faith, the team will be much more rapid at deploying updates.

Note the team is still fast at deploying updates especially bugs or Android Version Updates, since they are basically an ide and actual apps rely on it.

Note It sounds like I'm glazing, I'm not even affiliated, I'm really trying my best, but as Primeagan or PrimeTime or Theo said ::

If you only do frontend you are a Soy Boiiii 😭😭😭

I mix them up idk πŸ€·πŸ½β€β™‚οΈ, are they twins fr ?.

I do frontend (Vanilla just like Missionary), and use DroidScript, for mobile dev.
Me knowing node doesn't mean i know Backend.

Back to the topic,
Subscription cost of DroidScript is $0.49, I'm not going to lie that is well localized, in my country that definitely cant buy you a can of coke.

Yes id wish it was open source however developers working full time on this need to pay bills, offering something open source doesn't pay much, that is what is broken with open source.

I am lucky to be under parents arm since i just finished school and took a roundabout with a-levels so with the little time i have i can do open source before i start the stressful uni life.


Final words::

Do I recommend Droidscript:

Yes if you want to port a web app, or completely build one from the ground up. If you used React, use React Native, also there is NativeScript available.

Is It Worth Learning:

Yes and No, I worry too what-if the main developer gets tired and quits then what??, what if life's journey ends ?
What will happen...

These questions usually scare me, if your are an active user and contributor, especially with no cooperative backing, the project could expire.

Last Recommendation:

Learn something else while using it.
You can never regret knowledge.

Top comments (0)