react-native-sfsymbols

repository·main·Indexed 40 days ago

https://github.com/birkir/react-native-sfsymbols

A library for using Apple's SF Symbols in React Native applications on iOS 14+. It provides the SFSymbol component with support for configuring weight, scale, color, and multicolor mode, and is compatible with React Native's Animated API.

Tokens
1.6K
Snippets
7
Records
10
Agent score
0%

What's inside react-native-sfsymbols

  1. Manual installation for iOS

    main

    If you cannot use autolinking, follow these steps in Xcode:

    1. In Xcode, right-click Libraries ➜ Add Files to [your project's name].
    2. Navigate to node_modules/react-native-sfsymbols and add RNSfsymbols.xcodeproj.
    3. Select your project in the Xcode navigator.
    4. Go to Build Phases ➜ Link Binary With Libraries and add libRNSfsymbols.a.
    5. Run your project.
  2. Install react-native-sfsymbols

    main

    Install the package using npm or yarn, then ensure you install the iOS pods to link the native library.

    npm install --save react-native-sfsymbols
    
    # --- or ---
    
    yarn add react-native-sfsymbols
    
    # After installation, run:
    cd ios && pod install && cd ..
  3. Animate SFSymbol with React Native Animated

    main

    To use the Animated API with SF Symbols, wrap the component using Animated.createAnimatedComponent.

    import { Animated } from "react-native";
    import { SFSymbol } from "react-native-sfsymbols";
    
    const AnimatedSFSymbol = Animated.createAnimatedComponent(SFSymbol);
    
    // Usage
    <AnimatedSFSymbol
      name="sun.min.fill"
      style={{
        opacity: new Animated.Value(1),
      }}
    />;
  4. Use the SFSymbol component

    main

    Import SFSymbol from react-native-sfsymbols to render iOS SF Symbols. Note that this library is iOS 14+ only and does not support Android or other platforms.

    import { SFSymbol } from "react-native-sfsymbols";
    
    export function Example() {
      return (
        <SFSymbol
          name="thermometer.sun.fill"
          weight="semibold"
          scale="large"
          color="red"
          size={16}
          resizeMode="center"
          multicolor={false}
          style={{ width: 32, height: 32 }}
        />
      );
    }
  5. SFSymbol Props Reference

    main

    The SFSymbol component accepts the following props:

    • name (required): The symbol name (e.g., "sun.min.fill"). Refer to the SF Symbols application for valid names.
    • color (optional): Hex or color value. Supports PlatformColor and DynamicColorIOS.
    • weight (optional): The font weight of the symbol. Options: ultralight, light, thin, regular, medium, semibold, bold, heavy. Note: Multicolor mode may have issues with the thin weight.
    • scale (optional): Optimizes stroke thickness. Options: small, medium, large.
    • multicolor (optional): Boolean. Enable multicolor by setting this to true. Do not pass a color prop when using multicolor.
    • size (optional): The font size of the icon as a number.
    • resizeMode (optional): The resize mode of the icon. Defaults to center if size is provided, otherwise scale-aspect-fill. Options: scale-to-fill, scale-aspect-fit, scale-aspect-fill, redraw, center, top, bottom, left, right, top-left, top-right, bottom-left, bottom-right, cover, contain, stretch.
  6. Use the SFSymbol component

    main

    The SFSymbol component allows you to render Apple's SF Symbols in your React Native application. It wraps the native RNSfsymbols component and provides a high-level interface for configuring symbol appearance such as weight, scale, and color.

    import { SFSymbol } from 'react-native-sfsymbols';
    
    // Basic usage
    <SFSymbol name="heart.fill" />
    
    // Advanced usage with styling
    <SFSymbol 
      name="heart.fill" 
      color="red" 
      weight="bold" 
      scale="large" 
      size={40} 
    />
  7. Configure SFSymbolProps

    main

    The SFSymbol component accepts the following props to control its appearance:

    • name: (Required) The string identifier of the SF Symbol (e.g., "heart.fill").
    • color: (Optional) A ColorValue to set the symbol's color.
    • size: (Optional) A number representing the symbol size.
    • weight: (Optional) The thickness of the symbol lines. Use the SFSymbolWeight enum or a SymbolWeight string.
    • scale: (Optional) The scale of the symbol. Use the SFSymbolScale enum or a SymbolScale string.
    • multicolor: (Optional) A boolean to enable/disable multicolor support.
    • resizeMode: (Optional) Determines how the symbol scales. Use a SymbolResizeMode string.
    • style: (Optional) Standard React Native ViewStyle props.
  8. Reference SFSymbolWeight values

    main

    The SFSymbolWeight enum defines the available thickness levels for the symbol lines.

    export enum SFSymbolWeight {
      ULTRALIGHT = "ultralight",
      LIGHT = "light",
      THIN = "thin",
      REGULAR = "regular",
      MEDIUM = "medium",
      SEMIBOLD = "semibold",
      BOLD = "bold",
      HEAVY = "heavy",
    }
  9. Reference SymbolResizeMode values

    main

    The SymbolResizeMode type defines how the symbol should be resized within its container.

    type SymbolResizeMode =
      | "scale-to-fill"
      | "scale-aspect-fit"
      | "scale-aspect-fill"
      | "redraw"
      | "center"
      | "top"
      | "bottom"
      | "left"
      | "right"
      | "top-left"
      | "top-right"
      | "bottom-left"
      | "bottom-right"
      | "cover"
      | "contain"
      | "stretch";