-
Notifications
You must be signed in to change notification settings - Fork 46
Add a Component Page
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.sln
in 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());
.
Some modules are fine to include directly... others need to be patched from time to time. We use patch-package to accomplish this. As that this app is meant to be an example of best practices, open an issue and an issue on the source repo for the problem you are patching around.
- 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/examples
with the name "<Component>ExamplePage.tsx". - Copy the source code from
src/examples/TemplateExamplePage
into 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',
new: true
},
];
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. |
new | Set if true if your component is new. After each major release of Gallery, these values should be cleared. |
updated | Set if true if your component had significant updates. After each major release of Gallery, these values should be cleared. |
- Edit
__tests__/App-test.js
- Import your component
- Add a
test
method that invokes your component
import {FooExamplePage} from '../src/examples/FooExamplePage';
test('Foo Example Page', () => {
const tree = create(<FooExamplePage/>).toJSON();
expect(tree).toMatchSnapshot();
});
- Run the snapshot tests to generate changes to the
__tests__\__snapshots__\App-test.js.snap
file, which you should include in your commit