-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for scrollView.refreshControl #3597
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
change/react-native-windows-2019-11-05-11-31-02-refresh2.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Support refreshControl", | ||
| "packageName": "react-native-windows", | ||
| "email": "dida@ntdev.microsoft.com", | ||
| "commit": "7f7144f6708042a8e4983a143ef2733ac81abea5", | ||
| "date": "2019-11-05T19:31:02.270Z" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "pch.h" | ||
|
|
||
| #include "RefreshControlManager.h" | ||
|
|
||
| #include <winrt/Windows.UI.Xaml.Shapes.h> | ||
|
|
||
| #include <ReactUWP\Utils\Helpers.h> | ||
| #include <Views/ShadowNodeBase.h> | ||
|
|
||
| namespace winrt { | ||
| using namespace Windows::UI::Xaml; | ||
| using namespace Windows::UI::Xaml::Controls; | ||
| using namespace Windows::Foundation; | ||
| } // namespace winrt | ||
|
|
||
| namespace react { | ||
| namespace uwp { | ||
|
|
||
| class RefreshControlShadowNode : public ShadowNodeBase { | ||
| using Super = ShadowNodeBase; | ||
|
|
||
| public: | ||
| RefreshControlShadowNode(){}; | ||
| void createView() override; | ||
| void updateProperties(const folly::dynamic &&props) override; | ||
|
|
||
| private: | ||
| winrt::RefreshContainer::RefreshRequested_revoker m_refreshRequestedRevoker{}; | ||
| winrt::Deferral m_refreshDeferral{nullptr}; | ||
| }; | ||
|
|
||
| void RefreshControlShadowNode::createView() { | ||
| Super::createView(); | ||
| if (auto refreshContainer = GetView().try_as<winrt::RefreshContainer>()) { | ||
| m_refreshRequestedRevoker = | ||
| refreshContainer.RefreshRequested(winrt::auto_revoke, [this](auto &&, winrt::RefreshRequestedEventArgs args) { | ||
| auto wkinstance = GetViewManager()->GetReactInstance(); | ||
| if (auto instance = wkinstance.lock()) { | ||
| m_refreshDeferral = args.GetDeferral(); | ||
| folly::dynamic eventData = folly::dynamic::object(); | ||
| instance->DispatchEvent(m_tag, "topOnRefresh", std::move(eventData)); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| void RefreshControlShadowNode::updateProperties(const folly::dynamic &&props) { | ||
| if (auto refreshContainer = GetView().try_as<winrt::RefreshContainer>()) { | ||
| for (const auto &pair : props.items()) { | ||
| const std::string &propertyName = pair.first.getString(); | ||
| if (propertyName == "flexDirection") { | ||
| const folly::dynamic &propertyValue = pair.second; | ||
| if (propertyValue.isString() && propertyValue.asString() == "column") { // vertical scrollView | ||
| refreshContainer.PullDirection(winrt::RefreshPullDirection::TopToBottom); | ||
| } else { | ||
| refreshContainer.PullDirection(winrt::RefreshPullDirection::LeftToRight); | ||
| } | ||
| } else if (propertyName == "refreshing") { | ||
| const folly::dynamic &propertyValue = pair.second; | ||
| if (propertyValue.isBool()) { | ||
| bool refreshing = propertyValue.asBool(); | ||
| if (!refreshing && m_refreshDeferral) { | ||
| m_refreshDeferral.Complete(); | ||
| m_refreshDeferral = nullptr; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Super::updateProperties(std::move(props)); | ||
| } | ||
|
|
||
| RefreshControlViewManager::RefreshControlViewManager(const std::shared_ptr<IReactInstance> &reactInstance) | ||
| : Super(reactInstance) {} | ||
|
|
||
| facebook::react::ShadowNode *RefreshControlViewManager::createShadow() const { | ||
| return new RefreshControlShadowNode(); | ||
| } | ||
|
|
||
| const char *RefreshControlViewManager::GetName() const { | ||
| return "RCTRefreshControl"; | ||
| } | ||
|
|
||
| XamlView RefreshControlViewManager::CreateViewCore(int64_t tag) { | ||
| if (IsRS4OrHigher()) { | ||
| // refreshContainer is supported >= RS4 | ||
| return winrt::RefreshContainer(); | ||
| } else { | ||
| // just return a grid if refreshContainer is not supported | ||
| return winrt::Grid(); | ||
| } | ||
| } | ||
|
|
||
| void RefreshControlViewManager::AddView(XamlView parent, XamlView child, int64_t index) { | ||
| if (auto refreshContainer = parent.try_as<winrt::RefreshContainer>()) { | ||
| refreshContainer.Content(child.as<winrt::ScrollViewer>()); | ||
| } else if (auto grid = parent.try_as<winrt::Grid>()) { | ||
| grid.Children().Append(child.as<winrt::ScrollViewer>()); | ||
| } | ||
| } | ||
|
|
||
| folly::dynamic RefreshControlViewManager::GetNativeProps() const { | ||
| auto props = Super::GetNativeProps(); | ||
|
|
||
| props.update(folly::dynamic::object("refreshing", "boolean")); | ||
|
|
||
| return props; | ||
| } | ||
|
|
||
| folly::dynamic RefreshControlViewManager::GetExportedCustomDirectEventTypeConstants() const { | ||
| auto directEvents = Super::GetExportedCustomDirectEventTypeConstants(); | ||
| directEvents["topOnRefresh"] = folly::dynamic::object("registrationName", "onRefresh"); | ||
| return directEvents; | ||
| } | ||
| } // namespace uwp | ||
| } // namespace react |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <Views/FrameworkElementViewManager.h> | ||
|
|
||
| namespace react { | ||
| namespace uwp { | ||
|
|
||
| class RefreshControlViewManager : public FrameworkElementViewManager { | ||
| using Super = FrameworkElementViewManager; | ||
|
|
||
| public: | ||
| RefreshControlViewManager(const std::shared_ptr<IReactInstance> &reactInstance); | ||
|
|
||
| facebook::react::ShadowNode *createShadow() const override; | ||
|
|
||
| const char *GetName() const override; | ||
| folly::dynamic GetNativeProps() const override; | ||
| folly::dynamic GetExportedCustomDirectEventTypeConstants() const override; | ||
|
|
||
| protected: | ||
| XamlView CreateViewCore(int64_t tag) override; | ||
| void AddView(XamlView parent, XamlView child, int64_t index) override; | ||
| }; | ||
|
|
||
| } // namespace uwp | ||
| } // namespace react |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment for why you are doing this in code vs markup (I'm assuming this is a back compat thing?) #Resolved