react-native-macos/ReactAndroid
Guilherme Iscaro 5b953e51fa Revert Picker item original color (#25750)
Summary:
Since the Android's Picker implementation uses an ArrayAdapter,
it means that the views that were created may be reused for other items
in order to save memory. With this in mind, if one sets the Picker.Item
prop color for only certain items there might be an state that
some items that does not have the color set will end up appearing
with the wrong color. This happens because, this new item is
reusing a view of an item that had the color prop set.
In order to avoid this problem, once a new view is created
the ReactPickerAdapter will save the original color and
re-apply if the item does not have the color prop.

## Changelog

[Android] [Fixed] - Picker.Item displays wrong colors
Pull Request resolved: https://github.com/facebook/react-native/pull/25750

Test Plan:
On android execute the code below. Only the FIRST item should be red.

```javascript
import React from 'react';
import { StyleSheet, View, Picker } from 'react-native';

const values = new Array(100);

for (let i = 0; i < values.length; i += 1) {
  values[i] = (i * i).toString();
}

const App = () => {
  const [selected, setSelected] = React.useState(0);
  const onValueChange = React.useCallback((_, idx) => {
    setSelected(idx);
  }, []);
  return (
    <View style={styles.container}>
      <Picker onValueChange={onValueChange} selectedValue={values[selected]}>
        {values.map((v, i) => (
          <Picker.Item
            key={v}
            value={v}
            label={v}
            {...(!i ? { color: 'red' } : {})}
          />
        ))}
      </Picker>
    </View>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingHorizontal: 20,
  },
});

```

### Without the patch

You should see various items with the red color (when only the first one should be red)
![picker-not-working](https://user-images.githubusercontent.com/984610/61584012-fe902300-ab16-11e9-8131-62c471b7f753.gif)

### With the patch
Only the first item is red.

![picker-working](https://user-images.githubusercontent.com/984610/61584013-09e34e80-ab17-11e9-9ae0-95a513581779.gif)

Closes https://github.com/facebook/react-native/issues/25456

Differential Revision: D16430961

Pulled By: mdvacca

fbshipit-source-id: 48b41845d465df2e3dd34fc4a76950ddc75a010a
2019-07-23 23:38:39 -07:00
..
libs Upgrade Android support library to version 28 in RN 2019-01-22 10:44:53 -08:00
src Revert Picker item original color (#25750) 2019-07-23 23:38:39 -07:00
.npmignore Don't publish /ReactAndroid/build to npm, update version on master 2015-10-12 11:11:40 -07:00
DevExperience.md CHORE - Remove Trailing Spaces 2016-04-06 09:21:53 -07:00
README.md Fixing link to Android build guide. 2018-05-27 15:17:55 -07:00
build.gradle Release underlying resources when JS instance is GC'ed on Android 2019-07-09 02:20:55 -07:00
gradle.properties bump fresco to 2.0.0, supports AndroidX (#25358) 2019-06-22 23:37:10 -07:00
proguard-rules.pro Remove WebView from public RN interface 2019-03-28 17:37:05 -07:00
release.gradle Prepare Groovy scripts for Kotlin DSL migration (#23355) 2019-02-09 10:18:07 -08:00

README.md

Building React Native for Android

See the docs on the website.

Running tests

When you submit a pull request CircleCI will automatically run all tests. To run tests locally, see Testing.