Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When highlighting occurs, UI changes are bugged #9

Open
Douglas-Hsieh opened this issue Apr 20, 2022 · 3 comments
Open

When highlighting occurs, UI changes are bugged #9

Douglas-Hsieh opened this issue Apr 20, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@Douglas-Hsieh
Copy link

Douglas-Hsieh commented Apr 20, 2022

Hello, thank you for fixing the overlay flickering :)

I found another issue: When highlighting occurs, UI changes are bugged.

In this repro, changing the screens will work, but will stop working once highlighting occurs.

import React, { useState } from 'react';
import { Button } from 'react-native';
import { HighlightableElement, HighlightableElementProvider, HighlightOverlay } from 'react-native-highlight-overlay';

export default function App() {

  const [highlightId, setHighlightId] = useState<string>()
  const [screen, setScreen] = useState<string>('screen1')

  return (
    <HighlightableElementProvider>
      { screen === 'screen1' &&
        <HighlightableElement id="button1">
          <Button title={'button1'} onPress={() => {
            if (highlightId) {
              setHighlightId(null)
            } else {
              setHighlightId('button1')
            }
          }}/>
        </HighlightableElement>
      }

      { screen === 'screen2' &&
        <HighlightableElement id="button2">
          <Button title={'button2'} onPress={() => {
            if (highlightId) {
              setHighlightId(null)
            } else {
              setHighlightId('button2')
            }
          }}/>
        </HighlightableElement>
      }

      <Button title={'Change Screen'} onPress={() => {
        if (screen === 'screen1') {
          setScreen('screen2')
        } else {
          setScreen('screen1')
        }
      }}/>

      <HighlightOverlay
        highlightedElementId={highlightId}
        onDismiss={() => {}}
      />
    </HighlightableElementProvider>
  )
}
@Charanor
Copy link
Owner

Thank you for the code example, I'll take a look tomorrow. For now, can you try this but putting the check inside of the HighlightableElement?

<HighlightableElement id="button1">
  {screen === "screen1" && (
    <OtherComponent />
  )}
</HighlightableElement>

@Douglas-Hsieh
Copy link
Author

Douglas-Hsieh commented Apr 20, 2022

Nice, nesting the check inside the HighlightableElement worked!

I think it would be ideal to have it work in the first case as well

import React, { useState } from 'react';
import { Button } from 'react-native';
import { HighlightableElement, HighlightableElementProvider, HighlightOverlay } from 'react-native-highlight-overlay';

export default function App() {

  const [highlightId, setHighlightId] = useState<string>()
  const [screen, setScreen] = useState<string>('screen1')

  return (
    <HighlightableElementProvider>
        <HighlightableElement id="button1">
          { screen === 'screen1' &&
            <Button title={'button1'} onPress={() => {
              if (highlightId) {
                setHighlightId(null)
              } else {
                setHighlightId('button1')
              }
            }}/>
          }
        </HighlightableElement>

        <HighlightableElement id="button2">
          { screen === 'screen2' &&
            <Button title={'button2'} onPress={() => {
              if (highlightId) {
                setHighlightId(null)
              } else {
                setHighlightId('button2')
              }
            }}/>
          }
        </HighlightableElement>

      <Button title={'Change Screen'} onPress={() => {
        if (screen === 'screen1') {
          setScreen('screen2')
        } else {
          setScreen('screen1')
        }
      }}/>

      <HighlightOverlay
        highlightedElementId={highlightId}
        onDismiss={() => {}}
      />
    </HighlightableElementProvider>
  )
}

@Charanor
Copy link
Owner

Nice! I've updated the README to mention this as a caveat. I think I know why this is happening though, so I'll fix it when I get some time :) keeping this open for the time being so I don't forget 👀

@Charanor Charanor added the bug Something isn't working label May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants