[GH-ISSUE #108] onChange on initial start #65

Closed
opened 2026-05-05 11:36:47 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @mischnic on GitHub (May 5, 2018).
Original GitHub issue: https://github.com/kusti8/proton-native/issues/108

The onChanged event gets emitted when rendering the element for the first time (without any user interaction).

import React, { Component } from 'react';
import { render, Window, App, Entry, Box, ColorButton } from './src';

class Example extends Component {
  render() {
    return (
      <App>
        <Window
          title="Proton Native Rocks!"
          size={{ w: 300, h: 300 }}
          menuBar={false}
        >
          <Entry onChange={a => console.log(a)}>Some Text</Entry>
        </Window>
      </App>
    );
  }
}

render(<Example />);

Without typing anything:

$ npx babel-node test.js
Some Text
Originally created by @mischnic on GitHub (May 5, 2018). Original GitHub issue: https://github.com/kusti8/proton-native/issues/108 The onChanged event gets emitted when rendering the element for the first time (without any user interaction). ```jsx import React, { Component } from 'react'; import { render, Window, App, Entry, Box, ColorButton } from './src'; class Example extends Component { render() { return ( <App> <Window title="Proton Native Rocks!" size={{ w: 300, h: 300 }} menuBar={false} > <Entry onChange={a => console.log(a)}>Some Text</Entry> </Window> </App> ); } } render(<Example />); ``` Without typing anything: ``` $ npx babel-node test.js Some Text ```
Author
Owner

@kusti8 commented on GitHub (May 5, 2018):

I suspect this is due to the fact that it creates the onCreate callback before setting the text, simply because that's the order the props are given in. There really isn't an easy way to do this, unless you manually change the prop order which is a bit of a hack.

<!-- gh-comment-id:386816801 --> @kusti8 commented on GitHub (May 5, 2018): I suspect this is due to the fact that it creates the onCreate callback before setting the text, simply because that's the order the props are given in. There really isn't an easy way to do this, unless you manually change the prop order which is a bit of a hack.
Author
Owner

@mischnic commented on GitHub (May 5, 2018):

I suspect this is due to the fact that it creates the onCreate callback

onChange gets fired in DesktopComponent.initialProps:

d37dae1299/src/components/DesktopComponent.js (L200-L213)

<!-- gh-comment-id:386826983 --> @mischnic commented on GitHub (May 5, 2018): > I suspect this is due to the fact that it creates the onCreate callback `onChange` gets fired in `DesktopComponent.initialProps`: https://github.com/kusti8/proton-native/blob/d37dae1299527cfc51905b8eccdc1d398ebe413f/src/components/DesktopComponent.js#L200-L213
Author
Owner

@kusti8 commented on GitHub (May 5, 2018):

Yeah so once it sets the onChange callback, it sets the children as well. So if libui fires onChange when the text property is set, then that may be it. I still have to try it out and see.

<!-- gh-comment-id:386827286 --> @kusti8 commented on GitHub (May 5, 2018): Yeah so once it sets the onChange callback, it sets the children as well. So if libui fires onChange when the text property is set, then that may be it. I still have to try it out and see.
Author
Owner

@mischnic commented on GitHub (May 5, 2018):

It's libui-node('s "fault"):

void UiEntryBase::setText(std::string text) {
	uiEntrySetText(uiEntry(getHandle()), text.c_str());
	if (onChangedCallback != NULL) {
		(*onChangedCallback)();
	}
}

libui itself doesn't call onChanged with setText.

<!-- gh-comment-id:386828336 --> @mischnic commented on GitHub (May 5, 2018): It's libui-node('s "fault"): ```cpp void UiEntryBase::setText(std::string text) { uiEntrySetText(uiEntry(getHandle()), text.c_str()); if (onChangedCallback != NULL) { (*onChangedCallback)(); } } ``` libui itself doesn't call `onChanged` with `setText`.
Author
Owner

@kusti8 commented on GitHub (May 6, 2018):

Yeah that makes sense. It's not that big of a deal and it would be ugly to fix it in proton-native. For some applications that store the value, it may be desirable so that you get the default value, others not so much.

<!-- gh-comment-id:386895749 --> @kusti8 commented on GitHub (May 6, 2018): Yeah that makes sense. It's not that big of a deal and it would be ugly to fix it in proton-native. For some applications that store the value, it may be desirable so that you get the default value, others not so much.
Author
Owner

@parro-it commented on GitHub (May 7, 2018):

We can remove the callback change from the setter of property if you think it can improve things.

<!-- gh-comment-id:386974540 --> @parro-it commented on GitHub (May 7, 2018): We can remove the callback change from the setter of property if you think it can improve things.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/proton-native#65
No description provided.