Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 1.16 KB

File metadata and controls

31 lines (25 loc) · 1.16 KB

Lesson 14: More platform customization with the Platform module

In Lesson 13, we talked about module overrides for platform customization, but for smaller customizations, like selecting assets, we can use the Platform module from React Native to add conditional logic to cross-platform modules.

Using Platform.OS

Add a ternary expression to choose the ONNX model when Platform.OS === 'windows'.

  this.recognizer = new ImageRecognizer({
    model: Platform.OS === 'windows' 
      ? require('../../assets/model.onnx') 
      : require('../../assets/model.pb'),
    labels: require('../../assets/labels.txt'),
  });

Using Platform.select

The ternary or conditional expressions can get verbose when dealing with more than two platforms, so another option is to use Platform.select.

  this.recognizer = new ImageRecognizer({
    model: Platform.select({
      windows: require('../../assets/model.onnx'),
      default: require('../../assets/model.pb'),
    }),
    labels: require('../../assets/labels.txt'),
  });

Exit Criteria

  1. A fully working app that uses the camera and Windows ML to classify images captured by the device.