Skip to content

Commit

Permalink
Picker layout fix (WI:3391028) (#2584)
Browse files Browse the repository at this point in the history
* Forcing layout after adding new items to Picker

* Suggested code review change.
  • Loading branch information
KAnder425 authored and msftbot[bot] committed Jun 7, 2019
1 parent 4b0f471 commit b7916c4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions vnext/ReactUWP/Views/PickerViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ class PickerShadowNode : public ShadowNodeBase
PickerShadowNode();
void createView() override;
void updateProperties(const folly::dynamic&& props) override;
bool IsExternalLayoutDirty() const override { return m_hasNewItems; }
void DoExtraLayoutPrep(YGNodeRef yogaNode) override;

private:
void RepopulateItems();
static void OnSelectionChanged(IReactInstance& instance, int64_t tag, folly::dynamic&& value, int32_t selectedIndex, folly::dynamic&& text);

folly::dynamic m_items;
int32_t m_selectedIndex = -1;
bool m_hasNewItems = false;

// FUTURE: remove when we can require RS5+
bool m_isEditableComboboxSupported;
Expand All @@ -53,6 +56,17 @@ PickerShadowNode::PickerShadowNode()
m_isEditableComboboxSupported = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.Controls.ComboBox", L"IsEditableProperty");
}

void PickerShadowNode::DoExtraLayoutPrep(YGNodeRef yogaNode)
{
if (!m_hasNewItems)
return;

m_hasNewItems = false;

auto comboBox = GetView().try_as<winrt::ComboBox>();
comboBox.UpdateLayout();
}

void PickerShadowNode::createView()
{
Super::createView();
Expand Down Expand Up @@ -158,6 +172,7 @@ void PickerShadowNode::RepopulateItems()
comboboxItem.Foreground(BrushFrom(item["textColor"]));
comboBoxItems.Append(comboboxItem);
}
m_hasNewItems = true;
}
if (m_selectedIndex < static_cast<int32_t>(m_items.size()))
combobox.SelectedIndex(m_selectedIndex);
Expand Down

0 comments on commit b7916c4

Please sign in to comment.