### Installing React Native UILib Core Package (npm) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md This command installs the main `react-native-ui-lib` package from npm, which is the first step in integrating the library into a React Native project. It fetches the latest stable version of the UI library. ```bash npm install react-native-ui-lib ``` -------------------------------- ### Installing iOS Pods for React Native UILib Demo App Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md For iOS development, this command navigates into the `ios` directory of the demo app and executes `pod install`. This step resolves and installs all native iOS dependencies, which is crucial for building and running the demo app on iOS devices or simulators. ```bash cd ios && pod install ``` -------------------------------- ### Installing iOS Pods for React Native UILib Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md After installing JavaScript dependencies, this command navigates into the `ios` directory and runs `pod install` to fetch and link native iOS dependencies required by React Native UILib and its peer packages. This step is essential for iOS projects. ```bash cd ios && pod install ``` -------------------------------- ### Installing Dependencies for React Native UILib Demo App (yarn) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md This command uses Yarn to install all JavaScript dependencies listed in the `package.json` file of the cloned UILib demo application. It ensures all necessary Node.js modules are available for the project to run correctly. ```bash yarn ``` -------------------------------- ### Starting Metro Bundler for React Native UILib Demo App (yarn) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md This command initiates the Metro bundler, which compiles the JavaScript code and serves it to the React Native application. The bundler must be running in a separate terminal before launching the app on a device or emulator. ```bash yarn start ``` -------------------------------- ### Cloning React Native UILib Demo App Repository (git) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md These commands clone the official `react-native-ui-lib` GitHub repository to the local machine and then navigate into the newly created project directory. This is the initial step to access and run the UILib demo application. ```bash git clone git@github.com:wix/react-native-ui-lib.git cd react-native-ui-lib ``` -------------------------------- ### Installing Mandatory Peer Dependencies for React Native UILib (npm) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md This command installs `react-native-reanimated` and `react-native-gesture-handler`, which are crucial peer dependencies required for UILib's core animation and gesture functionalities. These packages enable advanced UI interactions. ```bash npm install react-native-reanimated react-native-gesture-handler ``` -------------------------------- ### Launching React Native UILib Demo App on iOS or Android (yarn) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md These commands are used to launch the React Native UILib demo application on either an iOS simulator/device (`yarn ios`) or an Android emulator/device (`yarn android`). One of these commands should be executed after the Metro bundler has started. ```bash yarn ios # or yarn android ``` -------------------------------- ### Defining Component-Specific Native Dependencies for React Native UILib (package.json) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md This snippet lists optional native dependencies and their recommended version ranges for specific UILib components, such as `@react-native-community/blur` for blur effects or `@react-native-community/netinfo` for network status. Developers should install only those relevant to their chosen components. ```json "@react-native-community/blur": ">=4.4.1" "@react-native-community/datetimepicker": "^3.4.6" "@react-native-community/netinfo": "^5.6.2" # Required for ConnectionStatusBar ``` -------------------------------- ### Installing Dependencies with Yarn Source: https://github.com/wix/react-native-ui-lib/blob/master/docuilib/README.md This command installs all necessary project dependencies using Yarn. It should be run after cloning the repository to set up the development environment. ```Shell $ yarn ``` -------------------------------- ### Defining Core Native Dependencies for React Native UILib (package.json) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/setup.md This snippet illustrates the required version ranges for `react-native-gesture-handler` and `react-native-reanimated` as they would appear in a `package.json` file. These dependencies are fundamental for UILib's core functionality, ensuring compatibility and stability. ```json "react-native-gesture-handler": "<=2.14.1" "react-native-reanimated": "<=3.16.7" ``` -------------------------------- ### Starting Local Development Server with Yarn Source: https://github.com/wix/react-native-ui-lib/blob/master/docuilib/README.md This command initiates a local development server for the Docusaurus website. It automatically opens a browser window and supports live reloading for most changes, eliminating the need for server restarts. ```Shell $ yarn start ``` -------------------------------- ### Installing eslint-plugin-uilib via npm Source: https://github.com/wix/react-native-ui-lib/blob/master/eslint-rules/README.md This snippet provides the command to install the `eslint-plugin-uilib` as a development dependency. It integrates the UI Lib specific rules into your ESLint setup. ```Shell npm install eslint-plugin-uilib --save-dev ``` -------------------------------- ### Installing ESLint via npm Source: https://github.com/wix/react-native-ui-lib/blob/master/eslint-rules/README.md This snippet shows the command to install ESLint as a development dependency using npm. ESLint is a prerequisite for using the `eslint-plugin-uilib`. ```Shell npm i eslint --save-dev ``` -------------------------------- ### Recommended Design Token Usage for Colors - JavaScript Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/v7.md This snippet illustrates the recommended way to apply colors in `react-native-ui-lib` v7 using design tokens. Instead of the deprecated `Colors.primary`, developers should use specific design tokens like `Colors.$backgorundPrimaryHeavy` to ensure consistency with the design system. This example shows the updated approach for setting a background color. ```javascript style={{backgroundColor: Colors.$backgorundPrimaryHeavy}} ``` -------------------------------- ### Loading Assets with react-native-ui-lib Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/assets.md This snippet demonstrates how to load UI assets using `Assets.loadAssetsGroup` from `react-native-ui-lib`. It shows examples of loading a simple asset group and nested asset groups for better organization, typically using `require()` to specify image paths. ```javascript import {Assets, Image} from 'react-native-ui-lib'; // Load a simple asset group Assets.loadAssetsGroup('icons', { icon1: require('icon1.png'), icon2: require('icon2.png'), icon3: require('icon3.png'), }); // Load nested asset groups for better organization Assets.loadAssetsGroup('illustrations.placeholders', { emptyCart: require('emptyCart.png'), emptyProduct: require('emptyProduct.png'), }); Assets.loadAssetsGroup('illustrations.emptyStates.', { noMessages: require('noMessages.png'), noContacts: require('noContacts.png'), }); ``` -------------------------------- ### Getting Color Tints Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/colors.md Explains how `Colors.getColorTint` can retrieve a specific tint from an existing system color (e.g., `Colors.green30` to `Colors.green70`) or generate a tint from a given hex color by creating an 8-tint palette. ```javascript import {Colors} from 'react-native-ui-lib'; Colors.getColorTint(Colors.green30, 70); // will return the value of Colors.green70 Colors.getColorTint('#ff2442', 50); // will return the 5th tint in an autogenerate 8-tints palette based on '#ff2442' ``` -------------------------------- ### Deprecated Colors.primary Usage in Styling - JavaScript Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/v7.md This snippet demonstrates the deprecated usage of `Colors.primary` for background styling in `react-native-ui-lib` v6. In v7, `Colors.primary` is no longer supported and should be replaced with specific design tokens for styling components. This example shows how `Colors.primary` was previously used directly in a style object. ```javascript style={{backgroundColor: Colors.primary}} ``` -------------------------------- ### Building a Welcome/Login Screen with React Native UI-Lib Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/usage.md This React Native snippet demonstrates the usage of UI-Lib components like `View`, `Text`, `SegmentedControl`, `TextField`, and `Button` to construct a basic welcome and login screen. It showcases common layout props (`flex`, `center`, `row`, `margin`), text styling (`blue50`, `text20`), input presets (`outline`), and button styling (`link`, `background-orange30`). The snippet creates a functional UI with options for registration/login and input fields. ```JavaScript function Example(props) { return (
Welcome
); } ``` -------------------------------- ### Building Static Website Content with Yarn Source: https://github.com/wix/react-native-ui-lib/blob/master/docuilib/README.md This command compiles the Docusaurus website into static content, placing the generated files in the `build` directory. The output can then be hosted on any static content hosting service. ```Shell $ yarn build ``` -------------------------------- ### Deploying to GitHub Pages with Yarn Source: https://github.com/wix/react-native-ui-lib/blob/master/docuilib/README.md This command facilitates the deployment of the website to GitHub Pages. It builds the site and pushes the generated content to the `gh-pages` branch, requiring the `GIT_USER` environment variable to be set with your GitHub username and `USE_SSH` to be true for SSH authentication. ```Shell $ GIT_USER= USE_SSH=true yarn deploy ``` -------------------------------- ### Loading Foundation Styles with React Native UI Lib Source: https://github.com/wix/react-native-ui-lib/blob/master/README.md This snippet demonstrates how to load global foundation styles like colors, typography, and spacings using react-native-ui-lib. It defines a custom color palette, typography scales (heading, subheading, body), and spacing values (page, card, gridGutter) to establish a consistent design system across the application. These configurations are loaded once and then applied automatically to UI Lib components. ```JavaScript // FoundationConfig.js import {Colors, Typography, Spacings} from 'react-native-ui-lib'; Colors.loadColors({ primaryColor: '#2364AA', secondaryColor: '#81C3D7', textColor: '##221D23', errorColor: '#E63B2E', successColor: '#ADC76F', warnColor: '##FF963C' }); Typography.loadTypographies({ heading: {fontSize: 36, fontWeight: '600'}, subheading: {fontSize: 28, fontWeight: '500'}, body: {fontSize: 18, fontWeight: '400'} }); Spacings.loadSpacings({ page: 20, card: 12, gridGutter: 16 }); ``` -------------------------------- ### Initializing React Native UI-Lib Component Drivers Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/testing.md This snippet illustrates the initialization of test drivers for specific UI-Lib components. Each driver is created by passing the `renderTree` (obtained from rendering the component) and a `testID` to uniquely identify the target component within the rendered tree. ```javascript const firstNameDriver = TextFieldDriver({renderTree, testID: 'firstName'}); const lastNameDriver = TextFieldDriver({renderTree, testID: 'lastName'}); const addressDriver = TextFieldDriver({renderTree, testID: 'address'}); const submitBtnDriver = ButtonDriver({renderTree, testID: 'submit'}); ``` -------------------------------- ### Using Themed Components in React Native UI Lib Source: https://github.com/wix/react-native-ui-lib/blob/master/README.md This React Native component demonstrates how to integrate and use UI Lib components with previously defined design system configurations. It showcases View, Text, Card, and Button components, applying global styles like padding-page, heading, body, padding-card, bg-primaryColor, and the custom square prop for the Button. This snippet highlights how the loaded foundations and component themes are automatically applied, simplifying UI development. ```JSX // MyScreen.js import React, {Component} from 'react'; import {View, Text, Card, Button} from 'react-native-ui-lib'; class MyScreen extends Component { render() { return ( My Screen This is an example card ); } } ``` -------------------------------- ### Importing Individual and Related Components in React Native UI Lib (JavaScript) Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/getting-started/packages.md This JavaScript snippet illustrates how to import specific UI components from `react-native-ui-lib` using individual packages, such as `View` and `Text`. It also shows how to import multiple related components, like those found within the `keyboard` package, to ensure only necessary code is included, optimizing application bundle size and performance. ```javascript // Import individual components import View from 'react-native-ui-lib/view'; import Text from 'react-native-ui-lib/text'; // Import multiple related components import { KeyboardTrackingView, KeyboardAwareInsetsView, KeyboardRegistry, KeyboardAccessoryView, KeyboardUtils } from 'react-native-ui-lib/keyboard'; ``` -------------------------------- ### Configuring ESLint Plugins for uilib Source: https://github.com/wix/react-native-ui-lib/blob/master/eslint-rules/README.md This JSON snippet demonstrates how to add `uilib` to the `plugins` section of your `.eslintrc` file. This step makes the `uilib` rules available for use in your project. ```JSON { "plugins": [ "uilib" ] } ``` -------------------------------- ### Loading Comprehensive Color Schemes for Dark/Light Mode Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/colors.md Demonstrates how to load extensive color schemes for both light and dark modes, including system colors and design tokens, to support dynamic theming across the application. ```javascript Colors.loadSchemes({ light: { screenBG: 'transparent', textColor: Colors.grey10, moonOrSun: Colors.yellow30, mountainForeground: Colors.green30, mountainBackground: Colors.green50, $backgroundSuccess: Colors.green40, $backgroundSuccessLight: Colors.green70 }, dark: { screenBG: Colors.grey10, textColor: Colors.white, moonOrSun: Colors.grey80, mountainForeground: Colors.violet10, mountainBackground: Colors.violet20, $backgroundSuccess: Colors.green40, $backgroundSuccessLight: Colors.green20 } }); ``` -------------------------------- ### Interacting with React Native UI-Lib Testkit Drivers Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/testing.md This code demonstrates how to simulate user interactions using the initialized test drivers. It shows how to change the text content of `TextField` components using `changeText` and how to simulate a button press using the `press` function on a `ButtonDriver`. ```javascript firstNameDriver.changeText('Musa'); lastNameDriver.changeText('The Man'); addressDriver.changeText('Yunitzman 5'); submitBtnDriver.press(); ``` -------------------------------- ### Verifying Code Standards with NPM Pre-Push Script Source: https://github.com/wix/react-native-ui-lib/blob/master/CONTRIBUTING.md This command is suggested to be run before submitting a Pull Request. It verifies that linting rules, TypeScript checks, and tests are not broken, ensuring code quality and stability before code submission. ```NPM Script npm run pre-push ``` -------------------------------- ### Rendering React Component for Testing Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/testing.md This code shows how to render a React component, `MyForm` in this case, within a test environment. The `render` function (presumably from a testing library like React Testing Library) returns a `renderTree` object, which is then used to initialize component drivers. ```javascript const renderTree = render(); ``` -------------------------------- ### Importing React Native UI-Lib Testkit Drivers Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/testing.md This snippet demonstrates how to import specific component drivers, `TextFieldDriver` and `ButtonDriver`, from the `react-native-ui-lib/testkit` module. These drivers are essential for interacting with UI-Lib components in a test environment. ```javascript import {TextFieldDriver, ButtonDriver} from 'react-native-ui-lib/testkit'; ``` -------------------------------- ### Loading Custom UI-Lib Style Presets in React Native Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/style.md This snippet demonstrates how to load custom color, typography, and spacing presets into `react-native-ui-lib`. It uses `Colors.loadColors`, `Typography.loadTypographies`, and `Spacings.loadSpacings` to define new style values like 'pink', 'gold', 'h1', 'h2', and 'page' spacing, making them available for use throughout the application. ```JSX import {Typography, Colors, Spacings} from 'react-native-ui-lib'; Colors.loadColors({ pink: '#FF69B4', gold: '#FFD700' }); Typography.loadTypographies({ h1: {fontSize: 58, fontWeight: '300', lineHeight: 80}, h2: {fontSize: 46, fontWeight: '300', lineHeight: 64} }); Spacings.loadSpacings({ page: isSmallScreen ? 16 : 20 }); ``` -------------------------------- ### Complete React Native UI-Lib Form Test Case Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/testing.md This comprehensive Jest test suite demonstrates a full end-to-end test for the `MyForm` component. It includes rendering the component, mocking the `onSubmit` handler, initializing and interacting with UI-Lib testkit drivers, and finally asserting the correct behavior of the form submission. ```javascript describe('My Form', () => { it('should submit MyForm with Musa The Man, Yunitzman 5', () => { const onSubmit = jest.fn(); const renderTree = render(); const firstNameDriver = TextFieldDriver({renderTree, testID: 'firstName'}); const lastNameDriver = TextFieldDriver({renderTree, testID: 'lastName'}); const addressDriver = TextFieldDriver({renderTree, testID: 'address'}); const submitBtnDriver = ButtonDriver({renderTree, testID: 'submit'}); firstNameDriver.changeText('Musa'); lastNameDriver.changeText('The Man'); addressDriver.changeText('Yunitzman 5'); submitBtnDriver.press(); expect(onSubmit).toHaveBeenCalledWith('Musa', 'The Man', 'Yunitzman 5'); }); }); ``` -------------------------------- ### Configuring Specific uilib ESLint Rules Source: https://github.com/wix/react-native-ui-lib/blob/master/eslint-rules/README.md This JSON snippet illustrates how to enable and configure individual `uilib` rules within the `rules` section of your `.eslintrc` file, setting their severity level (e.g., `2` for error). ```JSON { "rules": { "uilib/rule-name": 2 } } ``` -------------------------------- ### Loading Custom System Colors Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/colors.md Shows how to load a set of custom system colors into the `Colors` object, making them accessible throughout the app. These colors can then be referenced by name in components. ```javascript import {Colors} from 'react-native-ui-lib'; Colors.loadColors({ error: '#ff2442', success: '#00CD8B', text: '#20303C' }); ``` -------------------------------- ### Configuring uilib/component-deprecation Rules Source: https://github.com/wix/react-native-ui-lib/blob/master/eslint-rules/README.md This JavaScript and JSON snippet defines `deprecationWarnings` and `deprecationErrors` arrays, then shows how to configure `uilib/component-deprecation_warn` and `uilib/component-deprecation_error` rules. These rules help manage component migrations by providing warnings or errors for deprecated components and props, with optional auto-fix capabilities. ```JavaScript // deprecation message to warn you consumers about const deprecationWarnings = [ { "component": "ActivityIndicator", "source": "react-native", "message": "Please avoid using react-native ActivityIndicator, use the 'Loader' component instead" }, { "component": "OldComponent", "source": "react-native-ui-lib", "message": "Please use the 'NewComponent' instead. Auto fix available.", "fix": { "componentName": "NewComponent" } }, ]; const deprecationErrors = [ { "component": "Button", /// The component "source": "react-native-ui-lib", // The source you import the component from "message": "", "props": [ { "prop": "title", // the prop to depreciate "message": "Please use `label` prop instead of `title` prop", // custom message to the user "fix": { "propName": "label" } // provice auto fix } ] }, ]; // Two phases: warn & error to allow phasing your migration process { "rules": { 'uilib/component-deprecation_warn': ['warn', {deprecations: deprecationWarnings, dueDate: 'Thursday 31 January'}], 'uilib/component-deprecation_error': ['error', {deprecations: deprecationErrors , dueDate: 'Thursday 31 January' } } ``` -------------------------------- ### Applying UI-Lib Style Presets to a Text Component in React Native Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/style.md This snippet illustrates how to apply previously defined UI-Lib style presets directly to a `Text` component. By passing `h1` and `pink` as props, the component automatically uses the 'h1' typography and 'pink' color values loaded via `Typography.loadTypographies` and `Colors.loadColors` respectively, styling the 'Hello World' text. ```JSX Hello World ``` -------------------------------- ### Importing react-native-ui-lib Components (JavaScript/TypeScript) Source: https://github.com/wix/react-native-ui-lib/blob/master/extensions/rnuilib-snippets/README.md This snippet provides the essential import statement for react-native-ui-lib components, enabling their use within JavaScript or TypeScript React projects. It is typically generated by typing 'rnuilib' in the VS Code editor. ```JavaScript import {} from 'react-native-ui-lib' ``` -------------------------------- ### Configuring uilib/no-hard-coded-color Rule Source: https://github.com/wix/react-native-ui-lib/blob/master/eslint-rules/README.md This JavaScript and JSON snippet defines `validColors` and shows how to configure the `uilib/no-hard-coded-color` rule. It catches hard-coded color values and suggests replacement with predefined valid colors, improving consistency. ```JavaScript // Your app valid colors const validColors = { blue: '#459FED', red: '#F2564D', green: '#00CD8B', yellow: '#FFB600', } // Lint will catch all hard coded color values in the code and replace with valid colors if exist // `#459FED` will turn to `Colors.blue` { "rules": { "uilib/no-hard-coded-color": ['error', {validColors}] } } ``` -------------------------------- ### Building Development Assets and Checking TypeScript Errors Source: https://github.com/wix/react-native-ui-lib/blob/master/CONTRIBUTING.md This command must be executed before pushing new code, especially for new TypeScript files. It checks for TypeScript errors and generates declaration (.d.ts) files in the 'generatedTypes' folder, which must also be committed to the repository. ```NPM Script npm run build:dev ``` -------------------------------- ### Defining a React Native UI-Lib Form Component Source: https://github.com/wix/react-native-ui-lib/blob/master/docs/foundation/testing.md This JSX snippet defines a simple React Native form component, `MyForm`, which takes an `onSubmit` handler. It uses `TextField` components for input and a `Button` for submission, managing input values with React's `useState` hook. ```jsx import {Button, TextField, View} from 'react-native-ui-lib/testkit'; type OnSubmitHandler = (firstName: string, lastName: string, address: string) => void; const MyForm = (props: {onSubmit: OnSubmitHandler}) => { const {onSubmit} = props; const [firstName, setFirstName] = useState(''); const [lastName, setLastName] = useState(''); const [address, setAddress] = useState(''); return ( setFirstName(value)} value={firstName}/> setLastName(value)} value={lastName}/> setAddress(value)} value={address}/>