knowing when navcontroller.popbackstack is called in jetpack compose - kotlin

How can I know when navcontroller.popbackstack is called in jetpack compose?
I need a state or boolean value to understand if navcontroller.popbackstack is called to do something.

Related

TornadoFX - right way to instantiate decoupled controller?

I have a controller which has no direct coupling to the view classes, i.e. it subscribes to events from the event bus, and nothing else.
I'm arbitrarily creating it in the View class (by inject()), but it really doesn't need to be there. Is there a way to tell TornadoFX that it should be created otherwise?
TornadoFX doesn't do any annotation scanning, so there is no way to add a #Startup annotation or anything like that. The easiest way to make sure it's instantiated is actually injecting it into your App subclass. That makes for a pragmatic, yet clean and maintainable approach IMO :)
EDIT: It's actually better to use find(), to make sure that it's actually created right away, since inject() is lazy.
val ctrl = find<MyController>()

javaFX - Background Class API lacks?

Why there isn't possibility to change background color of existing Background object? (or I don't know it yet)
For example Region can have some background color, but you want to set the different one. Thing is that it takes Background type as the argument in the setter method. Then I need to make new object and use component's background setter from API because there isn't way (which I know) to use the old one object. Imo it looks ugly in some custom components inherited from these inside the API.
Futhermore there is possibility, there would be some references to the older Background preventing GC from releasing the memory if we won't set it to null explicitly.
Is my understanding correct? Can someone elaborate on the question from the beginning?

How to avoid extra calling of -textFieldDidEndEditing in some cases in objective c?

I have a tableview with customcells with textfields in it. I am facing a peculiar problem now:
When I tap on first row textfield, -beginEditing gets called.
Now I change the value and tap on second row textfield. So, the -didEndEditing of first row gets called. In this didEnd, I have some parsing methods which are called in some other class. But they are not executed now. Right after the didEnd, -beginEditing of second row text is called. After that the parsing happens. Till now, it is fine.
When the parsing is finished, objects from parsing is set in other classes,the flow should stop here, but I don't know from where and why, The -didEndEditing for the second row gets called ! Also, though any resignfirstresponder is not written anywhere, the keyboard gets dismissed !
Any clue why is this happening and how to solve it ?
This is the way Apple designed the system - all developers have to deal with it (right or wrong). The key is that you are given the "textField" property so you know WHICH one of the textFields is sending the delegate messages.
The solution is to use one or more mutable dictionaries (or some data structure) to keep state for each individual textField. You can have a primary dictionary that uses the textField object as the key, then for each textField a dictionary that has the current state, and any other info you want to retain about it.
You can probably hack a less elegant but easier to code solution to. In any case, there is overlap on these messages and there is not way to avoid it.
EDIT: use the tag as the key, or create a non-retained NSValue pointer object, but don't use the text field itself.

What is the purpose .parent in this Mtd?

I am trying to figure out the purpose of what the .parent property achieves in this method and the "get[ClassNameHere]" methods in general that feature this property being called.
-(HudLayer*) getHud
{
return (HudLayer*)[self.parent.parent.parent getChildByTag:kTagHudLayer];
}
It's not possible to know the details from just this method shown here. But the .parent does return the Cocos parent, sprite or layer, to which the current cocos object belongs as a child. Essentially this code suggests you have a sprite or layer with a child that has more children and more children of those children, and this is a way to find out who the big parent up the stream is, and then get a new child from that parent.
Personally it seems pretty sloppy to me. I'd never code that way myself. Hard to read (as you can see) and having so many parent properties strung together like this is opening a lot of room for bugs. It would be wiser if the top parent did what it needs to do rather than a distant grandchild going up the chain; it breaks the MVC model a bit to do it as shown here.
Probably class HudLayer has a parent property that points to another object of the same kind, thus having a parent property pointing to another HudLayer and so on, climbing up for three levels. Then it just sends a getChildByTag message to it.

MVVM light - Passing multiple parameters in RelayCommand from XAML

I have more than one PasswordBox on my view and I want to pass all their SecureStrings to my view model when I click a button.
My guess is that I want to populate an instance of a custom class with all the SecureStrings and pass that object as a parameter to the RelayCommand bound to the button.
If I only knew how...
My current idea for a work around:
In the RelayCommands action for the button: send out a NotificationMessageAction with a callback taking a custom class as parameter.
Register for that message in the views code behind, and then populate an object with the SecureStrings, and then pass that object back to the view model with the help of the callback. Not very nice...
There must be a better way to do this in XAML, right?
Actually, I think what you want to do is implement event handlers, or an attached behavior on your PaswordBoxes that will push the SecureStrings to properties in the same viewmodel object that will be handling the RelayCommand's action. Then your RelayCommand won't need any parameters at all.