Skip to content

Picker - Fix wrong offset when items change from search #3493

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

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

nitzanyiz
Copy link
Collaborator

@nitzanyiz nitzanyiz commented Jan 29, 2025

Description

Fixes bug where for some searched values in the Picker, the FlatList starts at an incorrect offset after the search. The FlatList items change, causing it to change its height and make it start the scroll at some negative offset. I've made it take the entire height that is left so this way the height will not change when the content changes so theres no jump.
I'm not sure if this is the correct solution. As it seems when the items change the FlatList goes under the TextInput, like having a negative offset so the picker item seems cut. After scrolling a little the item goes to its correct place and scroll resets correctly.

Steps to reproduce:

  1. Open the modal
  2. Search for Sh
  3. "Shell" item should be cut

Playground to reproduce:

import React, {Component} from 'react';
import {View, Picker} from 'react-native-ui-lib';

const options = [
  {label: 'Rust', value: 'rust'},
  {label: 'Dart', value: 'dart'},
  {label: 'Elixir', value: 'elixir'},
  {label: 'Haskell', value: 'haskell'},
  {label: 'Clojure', value: 'clojure'},
  {label: 'Lua', value: 'lua'},
  {label: 'Erlang', value: 'erlang'},
  {label: 'F#', value: 'fsharp'},
  {label: 'MATLAB', value: 'matlab'},
  {label: 'Shell', value: 'shell'},
  {label: 'SAS', value: 'sas'},
  {label: 'Solidity', value: 'solidity'},
  {label: 'Smalltalk', value: 'smalltalk'},
  {label: 'Scheme', value: 'scheme'},
  {label: 'Scratch', value: 'scratch'}
];
export default class PlaygroundScreen extends Component {
  render() {
    return (
      <View flex paddingT-s4>
        <Picker
          showSearch
          label="Select a language"
          items={options}
        />
      </View>
    );
  }
}

Changelog

Picker - Fixes incorrect offset after search.

Additional info

MADS-4601

@nitzanyiz nitzanyiz requested review from adids1221 and Inbal-Tish and removed request for adids1221 January 29, 2025 15:15
@nitzanyiz nitzanyiz marked this pull request as ready for review January 29, 2025 15:16
@@ -80,6 +80,13 @@ const PickerItemsList = (props: PickerItemsListProps) => {
return <PickerItem {...item}/>;
}, []);

const listPropsWithMergedStyles = useMemo(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply name it _listProps instead of listPropsWithMergedStyles

@Inbal-Tish Inbal-Tish assigned nitzanyiz and unassigned Inbal-Tish Jan 30, 2025
@Inbal-Tish
Copy link
Collaborator

Nice. Left a supper small commnet

@nitzanyiz nitzanyiz assigned Inbal-Tish and unassigned nitzanyiz Jan 30, 2025
@nitzanyiz nitzanyiz merged commit e27af1b into master Jan 30, 2025
1 check passed
@nitzanyiz nitzanyiz deleted the fix/PickerSeachFlatListScroll branch January 30, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants