-
Couldn't load subscription status.
- Fork 52
Add a Component Page
Chris Glein edited this page May 9, 2024
·
13 revisions
Make sure to follow the steps on the Contributing to React Native Gallery page to create a fork of the react-native-gallery repo and an a fresh branch which will contain the change to the repo you made in your page addition.
If you are adding a page for a core component you can skip this step; it is only necessary if you are working with a community module.
- Run
yarn add <community module>at the root of the repository.
Some older community module may not support autolinking. If that's the case follow these steps to manual link.
- Open up
windows/rngallery.slnin Visual Studio. - Add community module as an Existing Project to solution.
- Add community module project as a reference to rngallery project.
- Open pch.h and add
#include <winrt/\<module namespace\>.h>. - Open App.cpp and add
PackageProviders().Append(winrt::<module namespace\>::ReactPackageProvider());.
- Navigate to react-native-gallery repository in your local file system. Open repository by running
code .in your Command Line. This will ensure that the linter will properly format your code each time you save. - Create a new file in
src/exampleswith the name "<Component>ExamplePage.tsx". - Copy the source code from
src/examples/TemplateExamplePageinto your new file. - Follow the instructions provided in the comments on the page to replace the data used for the template page with the data for your component.
- If working with a core component use React Native website to see the list of prop options for the component.
- If working with a community module, visit the repository for the module to see the list of prop options for the component.
- Delete all comments from the page source code once you have correctly filled the page.
- Open
RNGalleryList.ts. - Underneath the import statements at the top of the page, import your new page. Follow the syntax of previously added pages as an example.
- Inside the RNGalleryList array, populate the properties to match your component (see below).
import {FooExamplePage} from './examples/FooExamplePage';
export const RNGalleryList: Array<IRNGalleryExample> = [
...
{
key: 'Foo',
component: FooExamplePage,
textIcon: '\uE734',
imageIcon: require('../assets/ControlImages/TextBlock.png'),
subtitle: 'A short description of this component.',
type: 'Text',
},
];
Where do these values come from?
| Prop | Source |
|---|---|
| key | A unique identifier for your page, used as the navigation route. |
| component | The actual component type. Will match what you exported. |
| textIcon | An entry in the Segoe MDL2 Assets font |
| imageIcon | Optional A full color image icon, matching WinUI gallery if a similar control exists |
| subtitle | A short description of your component, displayed on the component browsing pages. |
| type | One of the catgories of component pages, defined by the RNGalleryCategories array in the same file. |