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

android - sliding broken on RN 0.79 (rc3) #695

Open
vonovak opened this issue Mar 28, 2025 · 5 comments
Open

android - sliding broken on RN 0.79 (rc3) #695

vonovak opened this issue Mar 28, 2025 · 5 comments
Assignees
Labels
bug report Something isn't working new architecture Issue relates to react-native new architecture platform: Android Issue related to Android platform

Comments

@vonovak
Copy link
Contributor

vonovak commented Mar 28, 2025

Environment

New project initialized with RN 79 rc-3, with new architecture enabled

Description

Screen.Recording.2025-03-28.at.9.11.09.mov

Reproducible Demo

https://github.com/vonovak/slider-bug-79

@vonovak vonovak added the bug report Something isn't working label Mar 28, 2025
@BartoszKlonowski BartoszKlonowski added platform: Android Issue related to Android platform new architecture Issue relates to react-native new architecture labels Mar 28, 2025
@github-project-automation github-project-automation bot moved this to To be analyzed in Slider-Board Mar 28, 2025
@BartoszKlonowski BartoszKlonowski moved this from To be analyzed to In Progress in Slider-Board Mar 28, 2025
@BartoszKlonowski BartoszKlonowski self-assigned this Mar 28, 2025
@KostiantynSosonnyiEksperience

Same here, RN 77.2

@brimby
Copy link

brimby commented Apr 4, 2025

I think it's just handling the value prop differently now. Previously you could use onValueChange to set the state that fed directly into the slider's value prop. It would ignore the feedback loop until the interaction was complete and be fine. But now it seems to get hung up on it. You should try setting the value prop with onSlidingComplete instead. And if you want to show a display value as the slider moves, point onValueChange to a separate state used only for display.

So here's how you should change your reproducible demo (I added a displayValue state which is altered by onValueChange, and the original value state is now altered by onSlidingComplete) :

const [value, setValue] = React.useState(0.5);
const [displayValue, setDisplayValue] = React.useState(0.5);
return (
  <View style={backgroundStyle}>
    <StatusBar
      barStyle={isDarkMode ? 'light-content' : 'dark-content'}
      backgroundColor={backgroundStyle.backgroundColor}
    />

    <ScrollView style={backgroundStyle} ref={view}>
      <View style={{paddingRight: safePadding}}>
        <Header />
      </View>

      <View
        style={{
          backgroundColor: isDarkMode ? Colors.black : Colors.white,
          paddingHorizontal: safePadding,
          paddingBottom: safePadding,
        }}>
        <Text>Value: {displayValue && +displayValue.toFixed(3)}</Text>
        <Slider value={value} onValueChange={setDisplayValue} onSlidingComplete={setValue} />
        <Section title="Step One">
          Edit <Text style={styles.highlight}>App.tsx</Text> to change this
          screen and then come back to see your edits.
        </Section>
        <Section title="See Your Changes">
          <ReloadInstructions />
        </Section>
        <Section title="Debug">
          <DebugInstructions />
        </Section>
        <Section title="Learn More">
          Read the docs to discover what to do next:
        </Section>
        <LearnMoreLinks />
      </View>
    </ScrollView>
  </View>
);
}

@brimby
Copy link

brimby commented Apr 4, 2025

However, I'm not sure what the argument is (or if there even is one) for why you can't use onValueChange for the value prop anymore. So it might still be worth it for the devs to consider why this apparently changed.

@brianlenz
Copy link

I'm having this issue as well on React Native 0.78.2. We are not using new architecture, however. iOS works great, but in Android, the slider doesn't move at all. We update value, but the slider stays in place. If you drag the slider, the value is always 0 in onValueChanged (same behavior as in the screen recording ☝️).

@brianlenz
Copy link

@BartoszKlonowski I'm not entirely sure what the root cause of the issue is, but I was able to work around the bug by explicitly setting maximumValue={1}. I believe this is supposed to be the default, but it appears that it's not working correctly in RN 0.78.2. It worked previously without an explicit maximumValue in RN 0.76.9.

Here's pseudo-code:

<Slider
  value={position / duration || 0}
  maximumValue={1}
  minimumTrackTintColor={Colors.gray500}
  maximumTrackTintColor={Colors.gray300}
  thumbTintColor={Platform.select({
    ios: undefined,
    android: Colors.primary400,
  })}
  thumbImage={Platform.select({
    ios: TimelineThumb,
    android: undefined,
  })}
  onSlidingComplete={(value) => {
    void seekTo(value * duration);
  }}
  disabled={isLoading}
/>

Again, this issue only affects Android, not iOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something isn't working new architecture Issue relates to react-native new architecture platform: Android Issue related to Android platform
Projects
Status: In Progress
Development

No branches or pull requests

5 participants