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

enabled={false} not working on ios #575

Open
Gunndroid opened this issue Jun 29, 2024 · 2 comments
Open

enabled={false} not working on ios #575

Gunndroid opened this issue Jun 29, 2024 · 2 comments

Comments

@Gunndroid
Copy link

The picker remains enabled when I add the prop enabled={false}. I want to disabled the movement of the picker under certain conditions:

  {
    <Picker
      enabled={false}
      itemStyle={styles.itemStyle}
      style={styles.picker}
      selectedValue={isAdding ? 'add' : selectedHabit}
      onValueChange={itemValue => {
        if (itemValue === 'add') {
          setIsAdding(true);
        } else {
          setSelectedHabit(itemValue);
          onChangeHabit(itemValue);
        }
      }}>
      {habits.map((habit, index) => (
        <Picker.Item
          key={index}
          label={habit}
          value={habit}
          color={textColor}
        />
      ))}
      <Picker.Item label="+" value="add" color={textColor} />
    </Picker>
  }
@Maneesh27
Copy link

@Gunndroid are you able to solve this issue? If yes, please share your solution here, I am also facing this issue.

@lfalconr
Copy link

lfalconr commented Dec 4, 2024

I was abled to do a work around to make it to work for me. Apparently the property "enabled" is only available for Android at the time. To make it work on ios I had to encapsulate the Picker inside a View and use the pointerEvents property. When pointerEvents is none the view is unresponsive to touch events. I also made an special style for the picker when the platform is ios in order to reduce the opacity.

            <View pointerEvents={selectedCountryId === "Brasil" ? "auto" : "none"}>
                        <Picker
                            selectedValue={selectedStateId || ""}
                            style={selectedCountryId !== "Brasil" && Platform.OS === 'ios' && formDemandaStyles.pickerdisabled]}
                            onValueChange={(itemValue, itemIndex) => handleDropdownSelect(question.id, itemValue)}
                            enabled={selectedCountryId === "Brasil"}
                        >
                          <Picker.Item label="-- Selecione um estado --" value="" />
                          {question.states.map((state) => (
                              <Picker.Item key={state.id} label={state.name} value={state.name} />
                          ))}
                        </Picker>
              </View>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants