react-native-windows-samples icon indicating copy to clipboard operation
react-native-windows-samples copied to clipboard

question about ReactPackageProvider.idl for creating a native UI module

Open bibyzan opened this issue 3 years ago • 3 comments

When following the Sample ViewManager (C++) part of this tutorial

https://microsoft.github.io/react-native-windows/docs/view-managers

I just want to create the native view using visual c++ and the first line in the ViewManager(C++) tutorial says

For this sample, assume we already have the CustomUserControl defined in the C# example.

How can I create a native C++ view for use only within my existing react native project and not to create an entire native module for use by other people.

It's also unclear to me if the example given in the tutorial is possible with no C# code which I was trying to avoid in favor of only C++.

The part of the tutorial where you are supposed to create ReactPackageProvider.idl seems like it would be only if I was making a module for use in multiple projects, which I'm not, so any clarification here would be greatly appreciated.

Thanks

bibyzan avatar Oct 01 '20 23:10 bibyzan

@bibyzan great question. Yes, it is possible to create a pure C++ native module (in fact, we'd recommend C++ over C# for a number of reasons). We should update our documentation to articulate this better.

Regarding creating a WinRT component that implements a native module as a separate binary versus building the native module functionality into RNW: normally you would create this as a separate module. While it is possible to not create a module project and instead add a view manager in your own fork of the RNW code, this isn't really a scenario we expect people to follow for the most part.

Recently we have added the ability to create a native module from the CLI which would pre-populate the right files/project references etc. See https://microsoft.github.io/react-native-windows/docs/native-modules-setup#creating-a-blank-native-module-project

CC @stmoy @vmoroz

asklar avatar Oct 02 '20 01:10 asklar

Feedback on the sample seems to be that

  1. It's in C#, and doesn't make clear how to do this from a pure C++ perspective
  2. It leads you down the path of creating a community module, and doesn't make clear how to just access some native code in your app and not package that up for others

@bibyzan Does that capture what you're saying? @stmoy This looks like good feedback on the native module samples and a place where we have a gap.

chrisglein avatar Oct 12 '20 18:10 chrisglein

@chrisglein You've got it exactly, a friend of mine and I are doing a very dumb experiment where I am trying to use react native as a view/UI layer for a game we want to write using this C++ vulkan SDK https://vulkan.lunarg.com/sdk/home

I learned C++ years ago but never got any industry experience in the language specifically after that point. I have experience writing a react native module in swift for an iOS project and I was able to do that without making any package since I was kind of just messing around for now, I may decide to package it up later but it seemed simpler on iOS to not make a module and that's kind of what I was hoping I could do here.

bibyzan avatar Oct 12 '20 18:10 bibyzan