react-native-gesture-handler
react-native-gesture-handler copied to clipboard
Add Windows/UWP support
As the the react-navigation library now depends on this library, projects using react-navigation cannot be used on windows (see https://github.com/Microsoft/react-native-windows/issues/2033). Therefore it would be nice, if this library supported the UWP.
Yeah, I've just run in to this issue as we use mainly windows computers at work, so when I'm building the app on a Mac for iOS I'd like my team members to be able to use it on a windows computer too!
This should be easy enough to at least put a placeholder class that implements:
constants
State
{'UNDETERMINED', 'BEGAN', 'ACTIVE', 'CANCELLED', 'FAILED', 'END'}
Direction
: {'RIGHT', 'LEFT', 'UP', 'DOWN'}
methods
createGestureHandler()
attachGestureHandler()
updateGestureHandler()
dropGestureHandler()
handleSetJSResponder()
handleClearJSResponder()
Once those are in place, the library should actually run without errors. Adding actual native code to do what these methods should do could be done at a later phase.
I have no C# experience or I would take this on. If you use react-native-create-library on a windows machine, it will stub out the class. @JulianAssmann or @mikerodham do either of you have the knowledge to implement this?
I have absolutely no C# experience unfortunately otherwise I'd love to have helped out.
may I know if this has been resolved. it seems like able to run with Version 1.1.0, but, it breaks for android as for windows, it requires [email protected] while 1.1.0 only support the version starting from 0.58?
As a workaround, it's possible to patch the issue in a postinstall script by stubbing out the windows implementation using the web files. The following works with [email protected] and [email protected]:
[
'./node_modules/react-native-gesture-handler/createHandler.web.js',
'./node_modules/react-native-gesture-handler/Directions.web.js',
'./node_modules/react-native-gesture-handler/GestureHandlerButton.web.js',
'./node_modules/react-native-gesture-handler/PlatformConstants.web.js',
'./node_modules/react-native-gesture-handler/Swipeable.web.js',
].forEach(file => webToWindows(file));
Here imagine webToWindows()
takes a path and copies the contents to the same location, replacing .web
with .windows
. This isn't helpful if you need actual gesture support on windows, however.
What is the status of this. Seems like there is no immediate interest to support Windows with actual native code. I tried to play around with this but it seems rather difficult
As above mentioned, I got it working with:
You can create yourself a script at project root, mine is called webToWindowsRNGH.js
:
const fs = require("fs");
function callback(err) {
if (err) {
throw err;
}
console.log("Successfull!");
}
[
"./node_modules/react-native-gesture-handler/GestureHandlerButton.web.js",
"./node_modules/react-native-gesture-handler/PlatformConstants.web.js",
"./node_modules/react-native-gesture-handler/RNGestureHandlerModule.web.js"
].forEach((inputPath) => {
const splits = inputPath.split("./node_modules/react-native-gesture-handler/");
const newFileName = splits[1].replace(".web.js", ".windows.js");
const outputPath = "./node_modules/react-native-gesture-handler/" + newFileName;
console.log(`Trying to copy ${inputPath} to ${outputPath}`);
fs.copyFile(inputPath, outputPath, callback);
});
After that, adapt the package.json and add the postinstall script:
"postinstall": "node ./webToWindowsRNGH"