Skip to content

Commit 6653dcc

Browse files
committed
Add Windows implementation.
1 parent c2bd377 commit 6653dcc

38 files changed

+21784
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Check [getting started](https://docs.swmansion.com/react-native-gesture-handler/
1616

1717
Check out our dedicated documentation page for info about this library, API reference and more: [https://docs.swmansion.com/react-native-gesture-handler/docs/](https://docs.swmansion.com/react-native-gesture-handler/docs/)
1818

19+
For Windows-specific documentation, check out the [Windows README](windows/RNGestureHandler/README.md).
20+
1921
## Examples
2022

2123
If you want to play with the API but don't feel like trying it on a real app, you can run the example project. Clone the repo, go to the `Example/` folder and run:
@@ -28,9 +30,9 @@ If you are running on ios, run `pod install` in the ios folder
2830

2931
Run `yarn start` to start the metro bundler
3032

31-
Run `react-native run-android` or `react-native run-ios` (depending on which platform you want to run the example app on).
33+
Run `react-native run-android`, `react-native run-ios` or `react-native run-windows` (depending on which platform you want to run the example app on).
3234

33-
You will need to have an Android or iOS device or emulator connected as well as `react-native-cli` package installed globally.
35+
You will need to have an Android / iOS / Windows device or emulator connected as well as `react-native-cli` package installed globally.
3436

3537
## React native Support
3638

package-lock.json

Lines changed: 19503 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"react-native": "^0.63.4",
9393
"react-native-builder-bob": "^0.17.1",
9494
"react-native-web": "^0.11.7",
95+
"react-native-windows": "^0.63.0-0",
9596
"react-test-renderer": "16.8.6",
9697
"release-it": "^13.6.5",
9798
"typescript": "^4.1.2"

windows/RNGestureHandler/.gitignore

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
*AppPackages*
2+
*BundleArtifacts*
3+
4+
#OS junk files
5+
[Tt]humbs.db
6+
*.DS_Store
7+
8+
#Visual Studio files
9+
*.[Oo]bj
10+
*.user
11+
*.aps
12+
*.pch
13+
*.vspscc
14+
*.vssscc
15+
*_i.c
16+
*_p.c
17+
*.ncb
18+
*.suo
19+
*.tlb
20+
*.tlh
21+
*.bak
22+
*.[Cc]ache
23+
*.ilk
24+
*.log
25+
*.lib
26+
*.sbr
27+
*.sdf
28+
*.opensdf
29+
*.opendb
30+
*.unsuccessfulbuild
31+
ipch/
32+
[Oo]bj/
33+
[Bb]in
34+
[Dd]ebug*/
35+
[Rr]elease*/
36+
Ankh.NoLoad
37+
38+
# Visual C++ cache files
39+
ipch/
40+
*.aps
41+
*.ncb
42+
*.opendb
43+
*.opensdf
44+
*.sdf
45+
*.cachefile
46+
*.VC.db
47+
*.VC.VC.opendb
48+
49+
#MonoDevelop
50+
*.pidb
51+
*.userprefs
52+
53+
#Tooling
54+
_ReSharper*/
55+
*.resharper
56+
[Tt]est[Rr]esult*
57+
*.sass-cache
58+
59+
#Project files
60+
[Bb]uild/
61+
62+
#Subversion files
63+
.svn
64+
65+
# Office Temp Files
66+
~$*
67+
68+
# vim Temp Files
69+
*~
70+
71+
#NuGet
72+
packages/
73+
*.nupkg
74+
75+
#ncrunch
76+
*ncrunch*
77+
*crunch*.local.xml
78+
79+
# visual studio database projects
80+
*.dbmdl
81+
82+
#Test files
83+
*.testsettings
84+
85+
#Other files
86+
*.DotSettings
87+
.vs/
88+
*project.lock.json
89+
90+
#Files generated by the VS build
91+
**/Generated Files/**
92+

windows/RNGestureHandler/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# react-native-gesture-handler Windows Implementation
2+
3+
## Module Installation
4+
You can either use autolinking on react-native-windows 0.63 and later or manually link the module on earlier releases.
5+
6+
## Automatic install with autolinking on RNW >= 0.63
7+
RNGestureHandler supports autolinking. Just call: `npm i react-native-gesture-handler --save`
8+
9+
## Manual installation on RNW >= 0.62
10+
1. `npm install react-native-gesture-handler --save`
11+
2. Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`)
12+
3. Right-click Solution icon in Solution Explorer > Add > Existing Project...
13+
4. Add `node_modules\react-native-gesture-handler\windows\RNGestureHandler\RNGestureHandler.vcxproj`
14+
5. Right-click main application project > Add > Reference...
15+
6. Select `RNGestureHandler` in Solution Projects
16+
7. In app `pch.h` add `#include "winrt/RNGestureHandler.h"`
17+
8. In `App.cpp` add `PackageProviders().Append(winrt::RNGestureHandler::ReactPackageProvider());` before `InitializeComponent();`
18+
19+
## Module development
20+
21+
If you want to contribute to this module Windows implementation, first you must install the [Windows Development Dependencies](https://aka.ms/rnw-deps).
22+
23+
You must temporarily install the `react-native-windows` package. Versions of `react-native-windows` and `react-native` must match, e.g. if the module uses `react-native@0.62`, install `npm i react-native-windows@^0.62 --dev`.
24+
25+
Now, you will be able to open corresponding `RNGestureHandler.sln` file, e.g. `RNGestureHandler62.sln` for `react-native-windows@0.62`.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include "pch.h"
2+
#include "RNFlingHandler.h"
3+
4+
using namespace winrt::RNGestureHandler;
5+
using namespace winrt::Windows::UI::Input;
6+
using namespace winrt::Windows::UI::Xaml;
7+
using namespace winrt::Windows::UI::Xaml::Controls;
8+
using namespace winrt::Windows::UI::Xaml::Input;
9+
10+
void RNFlingGestureHandler::sendFlingEvent(winrt::Windows::Foundation::Point pos)
11+
{
12+
RNGestureHandlerEventExtraData eventData;
13+
14+
eventData.hasXY = true;
15+
eventData.x = pos.X;
16+
eventData.y = pos.Y;
17+
18+
eventData.hasAbsoluteXY = true;
19+
eventData.absoluteX = pos.X;
20+
eventData.absoluteY = pos.Y;
21+
22+
RNGestureHandlerEvent event{};
23+
event.viewTag = viewTag;
24+
event.handlerTag = handlerTag;
25+
event.state = RNGestureHandlerState::Active;
26+
event.prevState = lastState;
27+
event.extraData = &eventData;
28+
29+
sendEventsInState(RNGestureHandlerState::Active, &eventData);
30+
sendTouchEvent(&event);
31+
}
32+
33+
void RNFlingGestureHandler::onManipulationUpdated(winrt::Windows::Foundation::IInspectable const&,
34+
winrt::Windows::UI::Input::ManipulationUpdatedEventArgs const& e)
35+
{
36+
sendFlingEvent(e.Position());
37+
}
38+
39+
void RNFlingGestureHandler::onCrossSliding(winrt::Windows::Foundation::IInspectable const&,
40+
winrt::Windows::UI::Input::CrossSlidingEventArgs const& e)
41+
{
42+
VERBOSE_DEBUG("onCrossSliding\n");
43+
switch (e.CrossSlidingState())
44+
{
45+
case CrossSlidingState::Completed:
46+
sendEventsInState(RNGestureHandlerState::End, 0);
47+
sendEventsInState(RNGestureHandlerState::Undetermined, 0);
48+
break;
49+
default:
50+
sendFlingEvent(e.Position());
51+
break;
52+
}
53+
}
54+
55+
void RNFlingGestureHandler::onDragging(winrt::Windows::Foundation::IInspectable const&,
56+
winrt::Windows::UI::Input::DraggingEventArgs const& e)
57+
{
58+
VERBOSE_DEBUG("onDragging\n");
59+
switch (e.DraggingState())
60+
{
61+
case DraggingState::Completed:
62+
sendEventsInState(RNGestureHandlerState::End, 0);
63+
sendEventsInState(RNGestureHandlerState::Undetermined, 0);
64+
break;
65+
default:
66+
sendFlingEvent(e.Position());
67+
break;
68+
}
69+
}
70+
71+
void RNFlingGestureHandler::onManipulationCompleted(winrt::Windows::Foundation::IInspectable const&,
72+
winrt::Windows::UI::Input::ManipulationCompletedEventArgs const&)
73+
{
74+
sendEventsInState(RNGestureHandlerState::End, 0);
75+
sendEventsInState(RNGestureHandlerState::Undetermined, 0);
76+
}
77+
78+
void RNFlingGestureHandler::onPointerReleased(winrt::Windows::Foundation::IInspectable const& sender,
79+
winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
80+
{
81+
RNGestureHandler::onPointerReleased(sender, e);
82+
83+
sendEventsInState(RNGestureHandlerState::End, 0);
84+
sendEventsInState(RNGestureHandlerState::Undetermined, 0);
85+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include "../RNGestureHandler.h"
4+
5+
namespace winrt::RNGestureHandler
6+
{
7+
struct RNFlingGestureHandler : RNGestureHandler
8+
{
9+
void onManipulationUpdated(winrt::Windows::Foundation::IInspectable const& sender,
10+
winrt::Windows::UI::Input::ManipulationUpdatedEventArgs const& e) override;
11+
12+
void onManipulationCompleted(winrt::Windows::Foundation::IInspectable const& sender,
13+
winrt::Windows::UI::Input::ManipulationCompletedEventArgs const& e) override;
14+
15+
void onPointerReleased(winrt::Windows::Foundation::IInspectable const& sender,
16+
winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e) override;
17+
18+
void onCrossSliding(winrt::Windows::Foundation::IInspectable const& sender,
19+
winrt::Windows::UI::Input::CrossSlidingEventArgs const& e) override;
20+
21+
void onDragging(winrt::Windows::Foundation::IInspectable const& sender,
22+
winrt::Windows::UI::Input::DraggingEventArgs const& e) override;
23+
24+
void sendFlingEvent(winrt::Windows::Foundation::Point point);
25+
};
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "pch.h"
2+
#include "RNForceTouchHandler.h"
3+
4+
using namespace winrt::RNGestureHandler;
5+
using namespace winrt::Windows::UI::Input;
6+
using namespace winrt::Windows::UI::Xaml;
7+
using namespace winrt::Windows::UI::Xaml::Controls;
8+
using namespace winrt::Windows::UI::Xaml::Input;
9+
10+
void RNForceTouchGestureHandler::onManipulationUpdated(winrt::Windows::Foundation::IInspectable const&,
11+
winrt::Windows::UI::Input::ManipulationUpdatedEventArgs const&)
12+
{
13+
// Not available under UWP.
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include "../RNGestureHandler.h"
4+
5+
namespace winrt::RNGestureHandler
6+
{
7+
struct RNForceTouchGestureHandler : RNGestureHandler
8+
{
9+
void onManipulationUpdated(winrt::Windows::Foundation::IInspectable const& sender,
10+
winrt::Windows::UI::Input::ManipulationUpdatedEventArgs const& e) override;
11+
};
12+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "pch.h"
2+
#include "RNLongPressHandler.h"
3+
4+
using namespace winrt::RNGestureHandler;
5+
using namespace winrt::Windows::UI::Input;
6+
using namespace winrt::Windows::UI::Xaml;
7+
using namespace winrt::Windows::UI::Xaml::Controls;
8+
using namespace winrt::Windows::UI::Xaml::Input;
9+
10+
void RNLongPressGestureHandler::onHolding(winrt::Windows::Foundation::IInspectable const&,
11+
HoldingEventArgs const& e)
12+
{
13+
VERBOSE_DEBUG("onHolding\n");
14+
15+
RNGestureHandlerEventExtraData eventData;
16+
17+
eventData.hasXY = true;
18+
eventData.x = e.Position().X;
19+
eventData.y = e.Position().Y;
20+
21+
eventData.hasAbsoluteXY = true;
22+
eventData.absoluteX = e.Position().X;
23+
eventData.absoluteY = e.Position().Y;
24+
25+
sendEventsInState(RNGestureHandlerState::Active, &eventData);
26+
}
27+
28+
void RNLongPressGestureHandler::onPointerReleased(winrt::Windows::Foundation::IInspectable const& sender,
29+
winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
30+
{
31+
RNGestureHandler::onPointerReleased(sender, e);
32+
33+
sendEventsInState(RNGestureHandlerState::End, 0);
34+
sendEventsInState(RNGestureHandlerState::Undetermined, 0);
35+
}

0 commit comments

Comments
 (0)