How to make CodenameOne's RadioButton respect its image constants on its pressed state? - codenameone

I'm not sure if this is a bug or just something I'm missing.
I've added 2 multi-images to the constants "RadioSelectedImage" and "RadioUnselectedImage", and they work fine except in their pressed state. For example: the custom image I added to the unselected constant appears just fine in my RadioButton before any interaction, but when I press it, the image changes to the native image, and when I release it, it changes to my custom selected image as expected.
I thought the problem was with RadioButton's pressed UIID, but I don't see anything that could be changing its image. I'm deriving everything in the pressed state from the unselected state.
Furthermore, if I set the constant "IncludeNativeBool" to false, then it all works as expected, and my custom image appears even in the pressed state. I'd rather not do that though, since I rely on the native theme for some components in my app.
Am I missing something here or is this a bug? If it's the latter, is there a workaround?

It should be radioSelectedImage, radioUnselectedImage, radioSelectedFocusImage & radioUnselectedFocusImage.

Related

React & Canvas: changing state is breaking Canvas functions

I am trying to use a parent component to control animations in a child Canvas element. Specifically I want an animation to happen when a user inputs a correct answer.
It works until the user changes the state in the parent component, and then it no longer works.
I've made a stripped-back, minimal version of my code here to show my issue: https://codesandbox.io/s/epic-leaf-08jqvy?file=/src/App.js
My desired behaviour is that the red box bounces when a user clicks submit. That happens if they don't type anything in the input box, but as soon as you enter anything into there - changing state and re-rendering the component - the button no longer triggers the animation in the Canvas child component.
As far as I can tell, the issue is to do with changing the state when inputing text. If I make a version where the input is just assigned to a variable, it works fine, but I need to be able to use state and re-render other parts of it.
I have put a console.log in the jump() function, so I can see that it is being called, but no animation is taking place in the canvas.
I assume that what's happening is that everything is being re-rendered when the state changes, and so the useRef is no longer tracking to the right thing.
Things I've tried:
putting the canvas in a memoized component to prevent it from re-rendering
using eventlisteners to see if I can trigger the animations in other ways - keydown ones work, but I need the user to be able to type, so I tried other ones (like hashchange or audio.play) but neither of those worked.
You can see the thing I'm actually trying to build here: https://papaya-platypus-86565f.netlify.app/play Basically users answer questions and an animation plays depending on whether they're right or wrong, to give it a game-y feel.
Thanks!
I like your red box as well as your reasoning. Yes, the input state changing on keystroke is causing the entire App component to re-render. Note that your App.js component has a lot going on (all good stuff), such as your Box class instantiation, your canvas instantiation, etc.
The key is to break your components into smaller parts, particularly separating stateful components from non-stateful components. We don't want your canvas re-mounting on every input change, so we make them sibling components!
Here's a working example of your code, just in smaller components:
https://codesandbox.io/s/strange-julien-d3n4zm
I hope this helps.

React Material UI: floating label on something else than input

I made a custom component that doesn't rely on Input (it is actually showing a path selection within a tree)
I want to integrate this component in my application with the very same look and feel than any other input component. What I actually want is the floating label that takes place within the editor if the value is null or undefined, and floats above the editor if the editor has a value.
I can't find any way that permits to achieve this on components that are not based on an Input. Am I missing something in material ui documentation?
Here is the code sandbox of my development: https://codesandbox.io/s/treeviewselect-dj4j5?file=/demo.tsx
Edit: the boolean property shrink that should help to do the trick, but still, the position of the label is still off.
Edit2: it seems that the related control must have a height of 64px for the position of the label to be fine. Needs to pilot the whole behavior depending on the value. Will post the fully corrected codesandbox later.

Codename One - TextField appearance

I have a GUI built app and am trying to emulate the TextFIeld look of the Yahoo Mail page, where the underline of the TextField turns to blue when pressed.
I changed the "pressed" and "selected" state of the TextField UIID, but it only changes when I press it, but it doesn't stay that way and it turns back to grey.
Question:
Is there some kind of "toggle" function in TextFields as in CheckBoxes, so the new state stays that way?
Only selected state is used in text field (not pressed) and it should remain blue. It seems this is an issue with Codename One possibly a recent regression due to recent changes to text editing.
I've filed an issue on that here.

Is it possible to setup a toggle button when includeNativeBool is set to false?

According to the Developer Guide, to make a toggle button I should run setToggle(true) on a CheckBox. I couldn't get that to work at first, so I tried on a new theme and it worked just fine. After some experimentation I found that this only happens when includeNativeBool constant is set to false.
When I press the button, it changes to the pressed state, but when I release it, it changes back to the unselected/selected state. However, when I press it a second time, it doesn't change to the pressed state at all (maybe because it's internally "checked" already), and when I release it nothing happens. When I press it a third time, it behaves like the first, and so on.
I suggest not removing the includeNativeBool, you will run into basic complexities.
The toggle button works just as well without includeNativeBool but the the styles for ToggleButton won't be in the theme. Assuming you styled Button just use setUIID("Button");

Indeterminate state in Checkbox/ToggleButton changes to Unchecked on mouse over

I have a threestate RadioButton (same issue with ToggleButton) with a custom template in WPF (using Blend 4.0) and I turn it to 'Indeterminate' state on Load. This works fine, and I want to keep it in that state till the user clicks it. The problem is it changes to Unchecked state as soon as the user puts the mouse over it.
How can I prevent this unwanted change of state from happening? Is this the default behavior or something I might have changed accidentally?
I also would like that after clicked it would chang directly to the 'Checked' state but that's a different question and I've read it might have to do with changing the order of states.

Resources