React Native getting started
Install @britishairways-ent/bagel-react-native, load the BA fonts, and render a screen. Each component's props are on its page, under the React Native library option. To work on the library itself, use Storybook in the bagel-react-native repository, below. The release pass runs in a separate app, on the React Native QA process.
Install
The package is published to GitHub Packages, on the same registry as the web library. Create a personal access token and sign in with it, using the steps under With a javascript framework.
Point the @britishairways-ent scope at that registry. Add this to the .npmrc in the app:
@britishairways-ent:registry=https://npm.pkg.github.com
Then install the library:
npm install @britishairways-ent/bagel-react-native
The app also needs these peers. Versions below are the minimums.
- Always
react18.2 or newer, andreact-native0.73 or newer.react-native-safe-area-context4.5 or newer.BaScreenreads its insets.- Icons and links
react-native-svg15 or newer, forBaIconandBaLink.- Animation
react-native-reanimated3 or newer, forBaCarousel,BaCopyToClipboard, andBaDetails. An Expo app already includes the Reanimated Babel plugin. A bare app addsreact-native-reanimated/pluginas the last plugin inbabel.config.js. Reanimated 4 also needs a compatiblereact-native-worklets.- Copy to clipboard
@react-native-clipboard/clipboard1.14 or newer, forBaCopyToClipboard.
To use the package from GitHub Actions, request access the same way as for the web package. See GitHub Actions.
Fonts
Mylius Modern and Open Sans ship on bagelFontAssets. Load that map before rendering BaText, or the type falls back to the system font.
An Expo app uses expo-font:
import { useFonts } from 'expo-font';
import { bagelFontAssets } from '@britishairways-ent/bagel-react-native';
const [fontsLoaded] = useFonts(bagelFontAssets);
if (!fontsLoaded) return null;
A bare React Native app can use expo-font the same way, or pass those files to its own font loader.
First screen
Wrap the tree in SafeAreaProvider, then BaModeProvider. Put each screen in BaScreen, then BaPageSegment and BaContent. Omit theme. The screen and the segment follow the colour mode. Add BaScroll between the screen and the segments when the page scrolls. Scrolling is the next section.
import { useFonts } from 'expo-font';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import {
BaButton,
BaModeProvider,
BaScreen,
BaPageSegment,
BaContent,
BaText,
bagelFontAssets,
} from '@britishairways-ent/bagel-react-native';
export default function App() {
const [fontsLoaded] = useFonts(bagelFontAssets);
if (!fontsLoaded) return null;
return (
<SafeAreaProvider>
<BaModeProvider>
<BaScreen>
<BaPageSegment fill>
<BaContent>
<BaText variant="header28">Hello</BaText>
<BaButton variant="primary" onPress={() => {}}>
Continue
</BaButton>
</BaContent>
</BaPageSegment>
</BaScreen>
</BaModeProvider>
</SafeAreaProvider>
);
}
Scrolling
Put BaScroll inside BaScreen, and the segments inside the scroll view. Page margin stays on BaPageSegment, so the scroll indicator sits on the screen edge. The scroll view is on ba-scroll.
On a screen under native bottom tabs, set safeAreaBottom={false} on BaScreen. BaScroll defaults contentInsetAdjustmentBehavior to automatic, so on iOS the system can inset for the home indicator and an overlaying tab bar.
<BaScreen>
<BaScroll>
<BaPageSegment>
<BaContent>
<BaText variant="body16">Your trip</BaText>
</BaContent>
</BaPageSegment>
</BaScroll>
</BaScreen>
Colour mode
BaModeProvider follows the device. Light mode uses default (white). Dark mode uses midnight-700. Set the mode on ba-mode. The screen, scroll view, and segments are on ba-screen, ba-scroll, and ba-page-segment.
Set Expo userInterfaceStyle to "automatic". "light" keeps iOS in light mode, so the provider stays on the white theme.
Omit theme on a segment to follow the mode. Pass theme="sale" when that band should stay sale in both modes. Wrap neighbouring segments in BaPageSegmentGroup so matching themes share one block of padding.
<BaScreen>
<BaPageSegmentGroup>
<BaPageSegment>
<BaContent>
<BaText variant="header28">Your trip</BaText>
</BaContent>
</BaPageSegment>
<BaPageSegment theme="sale">
<BaContent>
<BaText variant="header20">Sale fares</BaText>
</BaContent>
</BaPageSegment>
</BaPageSegmentGroup>
</BaScreen>
Develop with Storybook
Storybook lives in the bagel-react-native repository and runs through the example/ app. It is where a component is built and reviewed while you work on the library. It is separate from the release pass, which runs in bagel-qa-react-native.
From the library repository:
npm install- Installs the library and the example app.
npm run build- Builds the package the example app loads.
npm run storybook- Starts Storybook for the example app.
npm run storybook:ios- Opens Storybook in the iOS Simulator.
npm run storybook:android- Opens Storybook in the Android Emulator.
Those scripts set EXPO_PUBLIC_STORYBOOK_ENABLED=true. Storybook has on-device controls for props such as theme and locale. The screen size is the simulator, emulator, or device you run it on.