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

useState callback do not execute inside onSlidingComplete using tap. #547

Open
gibo77 opened this issue Oct 20, 2023 · 1 comment
Open
Labels
bug report Something isn't working platform: Android Issue related to Android platform

Comments

@gibo77
Copy link

gibo77 commented Oct 20, 2023

Environment

Android has issue.
iOS it works.

  • react-native info output:
// react-native info
 "dependencies": {
    "@react-native-community/slider": "^4.4.2",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "babel": "^6.23.0",
    "base64-js": "^1.5.1",
    "buffer": "^6.0.3",
    "react": "18.2.0",
    "react-native": "0.72.4",
    "react-native-gesture-handler": "^2.12.1",
    "react-native-reanimated": "^3.5.1",
    "react-native-safe-area-context": "^4.7.2",
    "react-native-screens": "^3.25.0",
    "react-native-size-matters": "^0.4.0",
    "react-native-splash-screen": "^3.3.0",
    "react-native-udp": "^4.1.7",
    "react-native-vector-icons": "^10.0.0",
    "upgrade": "^1.1.0"
  • are you using the new architecture?

  • which version of react & react-native are you using?

Description

The val inside the onSlidingComplete is updated when using tap in Android.
But using val in useState setSliderBrightness does not change the SliderBrightness value.

Reproducible Demo

 const [SliderBrightness, setSliderBrightness] = useState(valueItem);

  <Slider
              style={styles.SliderMargin}
              step={1}
              disabled={!isEnabled} //If Glowing is activated, the Slider could not be changed.
              tapToSeek={true}
              minimumTrackTintColor="#307ecc"
              maximumTrackTintColor="#000000"
              maximumValue={100}
              minimumValue={0}
              value={SliderBrightness} //Updates on real time. Excellent.
              onSlidingComplete={val => {
                val => setSliderBrightness(val);
                console.log('OnSlidingComplete: ', SliderBrightness);
                ChangeBrightnessHappened = true;
                //setSliderBrightness(val);
                Gibo_Fetch('IGBT=' + val + '&Angga=' + ESPSerialNum);
                // navigation.setParams({valueItem: SliderBrightness});
              }}
              onValueChange={val => setSliderBrightness(val)}
            />

@gibo77 gibo77 added the bug report Something isn't working label Oct 20, 2023
@BartoszKlonowski BartoszKlonowski added this to To be analyzed in Slider-Board via automation Oct 20, 2023
@gibo77
Copy link
Author

gibo77 commented Oct 20, 2023

Hi Team,
I was able to get a solution on my issue. Since I couldn't make the useState work inside the "OnFinishSliding", I just created my own function or callback and pass the val, as such FuncSlider(val).
In the callback function I was able to update my variable SliderBrightness by equaling it to val, so that when I return back to home page I have the correct val data.

This val parameter is not in the documentation. I just found out about it somewhere in an example by chance. It would be nice to have it in documentation.

@BartoszKlonowski BartoszKlonowski added the platform: Android Issue related to Android platform label Feb 6, 2024
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 platform: Android Issue related to Android platform
Projects
Slider-Board
  
To be analyzed
Development

No branches or pull requests

2 participants