npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hms-scan-view

v2.1.1

Published

hms-scan-view

Readme

hms-scan-view

hms-scan-view-react-navite

Installation

npm install hms-scan-view

Setting ios

Add the following to ios/Runner/Info.plist

<key>NSCameraUsageDescription</key>
<string>Explain to the user here why you need the permission</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Explain to the user here why you need the permission</string>

Setting android

<!--相机权限-->
<uses-permission android:name="android.permission.CAMERA" />
<!--文件读取权限,Android 12及更低版本申请-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!--读存储(媒体和文件)权限,Android 13及更高版本申请-->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>

Usage

import { HmsScanView } from 'hms-scan-view';
import type { ScanResult, CutArea, HmsScanViewRef } from 'hms-scan-view';
import { Text, View, StyleSheet, Switch, Button } from 'react-native';
import { useState, useRef } from 'react';

export default function App() {
  const [scanResult, setScanResult] = useState<ScanResult | null>(null);
  const [useCutArea, setUseCutArea] = useState(false);
  const [continuousScan, setContinuousScan] = useState(true);
  const scanViewRef = useRef<HmsScanViewRef>(null);

  // 自定义扫码区域 - 中心100x100的区域
  const customCutArea: CutArea = {
    x: 150, // 从左侧开始的位置
    y: 200, // 从顶部开始的位置
    width: 200, // 宽度
    height: 200, // 高度
  };

  const handleScanResult = (result: ScanResult) => {
    console.log('扫描结果:', result);
    setScanResult(result);
  };

  // 暂停扫描
  const handlePauseScan = () => {
    if (scanViewRef.current) {
      scanViewRef.current.pauseContinuouslyScan();
    }
  };

  // 恢复扫描
  const handleResumeScan = () => {
    if (scanViewRef.current) {
      scanViewRef.current.resumeContinuouslyScan();
    }
  };

  return (
    <View style={styles.container}>
      {scanResult ? (
        <View style={styles.resultContainer}>
          <Text style={styles.resultTitle}>扫描结果:</Text>
          <Text style={styles.resultText}>{scanResult.text || JSON.stringify(scanResult)}</Text>
        </View>
      ) : (
        <Text style={styles.instructions}>请扫描二维码或条形码</Text>
      )}
      
      <View style={styles.optionsContainer}>
        <View style={styles.optionRow}>
          <Text>使用自定义扫码区域: </Text>
          <Switch
            value={useCutArea}
            onValueChange={setUseCutArea}
          />
        </View>
        
        <View style={styles.optionRow}>
          <Text>连续扫描: </Text>
          <Switch
            value={continuousScan}
            onValueChange={setContinuousScan}
          />
        </View>
        
        {continuousScan && (
          <View style={styles.buttonContainer}>
            <Button title="暂停扫描" onPress={handlePauseScan} />
            <View style={{ width: 10 }} />
            <Button title="恢复扫描" onPress={handleResumeScan} />
          </View>
        )}
      </View>
      
      <View style={styles.scannerContainer}>
        <HmsScanView 
          ref={scanViewRef}
          style={styles.scanner} 
          onScanResult={handleScanResult}
          cutArea={useCutArea ? customCutArea : undefined}
          continuouslyScan={continuousScan}
        />
        
        {/* 如果启用了自定义扫码区域,显示一个指示框 */}
        {useCutArea && (
          <View 
            style={[
              styles.cutAreaIndicator, 
              {
                left: customCutArea.x,
                top: customCutArea.y,
                width: customCutArea.width,
                height: customCutArea.height,
              }
            ]} 
          />
        )}
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    padding: 20,
  },
  scannerContainer: {
    width: '100%',
    height: 500,
    marginTop: 20,
    overflow: 'hidden',
    borderRadius: 8,
    position: 'relative', // 添加相对定位,以便cutAreaIndicator可以相对于它定位
  },
  scanner: {
    flex: 1,
  },
  instructions: {
    fontSize: 16,
    marginBottom: 20,
    textAlign: 'center',
  },
  resultContainer: {
    width: '100%',
    padding: 15,
    backgroundColor: '#f0f0f0',
    borderRadius: 8,
    marginBottom: 20,
  },
  resultTitle: {
    fontSize: 18,
    fontWeight: 'bold',
    marginBottom: 10,
  },
  resultText: {
    fontSize: 14,
  },
  // 选项容器样式
  optionsContainer: {
    width: '100%',
    marginBottom: 15,
  },
  // 选项行样式
  optionRow: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    marginBottom: 10,
  },
  // 按钮容器样式
  buttonContainer: {
    flexDirection: 'row',
    justifyContent: 'center',
    marginTop: 10,
    marginBottom: 10,
  },
  // 添加自定义扫码区域开关的样式
  cutAreaToggle: {
    flexDirection: 'row',
    alignItems: 'center',
    marginBottom: 10,
  },
  // 添加自定义扫码区域指示框的样式
  cutAreaIndicator: {
    position: 'absolute',
    borderWidth: 2,
    borderColor: 'red',
    backgroundColor: 'rgba(255, 0, 0, 0.1)',
  },
});

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library