sohobloo / react-native-modal-dropdown

A react-native dropdown/picker/selector component for both Android & iOS.
MIT License
1.19k stars 478 forks source link

adjustFrame returning top property as NaN when parent View justifyContent is set. #189

Open cesargutierrezo opened 6 years ago

cesargutierrezo commented 6 years ago

I use adjustFrame to move my option dropdown a bit lower by adding a few pixels to the adjustFrame style object. As soon as I set the parent View style to justifyContent: center, the dropdown started rendering at the top of the screen instead of the calculated top I had set. Soon I found out the top property was returning NaN.

Has this happened to anyone else?

Problem: image

Regular behavior: image

cesargutierrezo commented 6 years ago

I just found out what the problem was. I was setting the dropdown height to 'auto' which messed up the position calculation.

const positionStyle = {
      height: dropdownHeight,
      top: showInBottom ? this._buttonFrame.y + this._buttonFrame.h : Math.max(0, 
      this._buttonFrame.y - dropdownHeight),
};

console.log(showInBottom) // Returns NaN because dropdownHeight is set to 'auto' instead of an actual number

I don't know if this is something that could be fixed but for now I'll set up a fixed height.

srdjanbogicevic commented 5 years ago

I had exactly the same problem. Your comment saved my day. Thanks.

velialiev commented 3 years ago

I just found out what the problem was. I was setting the dropdown height to 'auto' which messed up the position calculation.

const positionStyle = {
      height: dropdownHeight,
      top: showInBottom ? this._buttonFrame.y + this._buttonFrame.h : Math.max(0, 
      this._buttonFrame.y - dropdownHeight),
};

console.log(showInBottom) // Returns NaN because dropdownHeight is set to 'auto' instead of an actual number

I don't know if this is something that could be fixed but for now I'll set up a fixed height.

You saved my night too