Skip to content

hesengineering/react-native-compass-heading

 
 

Repository files navigation

react-native-compass-heading

credits - https://github.com/vnil/react-native-simple-compass

Installation

$ yarn add react-native-compass-heading

$ cd ios/ && pod install && cd ..

Usage

import React, {useState, useEffect} from 'react';
import {Image, StyleSheet} from 'react-native';
import CompassHeading from 'react-native-compass-heading';

const App = () => {
  const [compassHeading, setCompassHeading] = useState(0);

  useEffect(() => {
    const degree_update_rate = 3;

    CompassHeading.start(degree_update_rate, degree => {
      setCompassHeading(degree);
    });

    return () => {
      CompassHeading.stop();
    };
  }, []);

  return (
    <Image
      style={[
        styles.image,
        {transform: [{rotate: `${360 - compassHeading}deg`}]},
      ]}
      resizeMode="contain"
      source={require('./compass.png')}
    />
  );
};

const styles = StyleSheet.create({
  image: {
    width: '90%',
    flex: 1,
    alignSelf: 'center',
  },
});

export default App;

About

React Native module for iOS & Android to receive compass heading

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 40.7%
  • Objective-C 24.2%
  • Ruby 23.4%
  • JavaScript 9.4%
  • Starlark 2.3%