recycle icon indicating copy to clipboard operation
recycle copied to clipboard

sources.select doesn't work in React Native elements

Open italonascimento opened this issue 7 years ago • 10 comments

When I try to add a listener to a React Native element, nothing happens.

In my update:

sources.select('Button').addListener('onPress')
  .reducer(...)

In my view:

<Button title="Go" />

It seems like recycle cannot select the Button element. Tried to figure it out, but can't find the reason.

italonascimento avatar Nov 22 '17 16:11 italonascimento

I am having the same issue here. Also, i don't think it is React Native related, cuz i am using regular React. Wondering if it has something to do with #24

PS: Maybe it's better to rename the issue and make it more generic @italonascimento

edunuzzi avatar Nov 26 '17 19:11 edunuzzi

Could someone please make a simple repo (or just a snippet) where I can reproduce the issue?

I've tried selecting button using "simple example" and it seems to work as expected...

domagojk avatar Nov 26 '17 21:11 domagojk

I created a repo with a simplified version of my issue: https://github.com/edunuzzi/recycle-snippet

By some reason, recycle can't seem to select '#login-input'

edunuzzi avatar Nov 27 '17 18:11 edunuzzi

Thanks @edunuzzi! I guess there's no way a React Native repo would be any simple.

italonascimento avatar Nov 27 '17 18:11 italonascimento

Maybe it has something to do with React 16?

italonascimento avatar Nov 27 '17 18:11 italonascimento

@edunuzzi You should define your jsx views as functions.

so instead of

view: () => loginPageView
export const loginPageView =
    <div>
        <form id='form'>
            <input id='login-input' placeholder="email ou CPF"/>
            <input id='login-password' type="password" placeholder="senha"/>
            <button type="submit">Entrar</button>
        </form>
    </div>

try using

view: loginPageView
export const loginPageView = () =>
    <div>
        <form id='form'>
            <input id='login-input' placeholder="email ou CPF"/>
            <input id='login-password' type="password" placeholder="senha"/>
            <button type="submit">Entrar</button>
        </form>
    </div>

and let me know if it works?

domagojk avatar Nov 27 '17 22:11 domagojk

@italonascimento can you paste a snippet of a complete (or stripped) recycle component you are using and I will try to reproduce the issue in react native

domagojk avatar Nov 27 '17 22:11 domagojk

Oh, that actually solved my problem! That was subtle! Thanks a lot 👍 @domagojk

edunuzzi avatar Nov 28 '17 11:11 edunuzzi

@italonascimento Have you figured it out yet?

edunuzzi avatar Nov 28 '17 11:11 edunuzzi

I'm not very experienced in React native, but as I can see, there is no native Button component so you can't listen to onPress on it.

This is done by TouchableHighlight https://facebook.github.io/react-native/docs/touchablehighlight.html on which you can listen for press events:

sources.select(TouchableHighlight).addListener('onPress')

If that doesn't fix your problem, can you try to write your component without recycle? If in that case onPress event is working fine, we would know for sure there's a bug in Recycle and not in your code.

domagojk avatar Nov 29 '17 00:11 domagojk