1.1.2 • Published 12 months ago

react-native-qibla-finder v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

QiblaFinder

QiblaFinder is a component for React Native that displays the Qibla direction and compass functionality. This component provides dynamic updates based on device sensor data and offers visual feedback on the Qibla and compass directions.

Installation

To install the package using Yarn and Npm, run the following command:

from yarn:

yarn add react-native-qibla-finder

from npm:

npm install react-native-qibla-finder

Note For iOS using cocoapods, run:

$ cd ios/ && pod install

If you are using Expo, you can start using the package right away. However, if you are using React Native CLI, additional configurations are required.

Additional Setup for React Native CLI

If you are using React Native CLI, you need to install and configure expo-modules. Follow the steps provided in the Expo Modules Installation Guide.

from npm:

npm install expo expo-modules-core expo-sensors expo-location

from yarn:

yarn add expo expo expo-modules-core expo-sensors expo-location

Note For iOS using cocoapods, run:

$ cd ios/ && pod install

Configuration for iOS

Below is an example of how to modify your ios/myapp/AppDelegate.h file:

#import <RCTAppDelegate.h>
+ #import <Expo/Expo.h>
#import <UIKit/UIKit.h>

- @interface AppDelegate : RCTAppDelegate
+ @interface AppDelegate : EXAppDelegateWrapper

@end

Below is an example of how to modify your ios/Podfile file:

+ require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")

# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['--print',
  'require.resolve'
end

target 'myapp' do
+   use_expo_modules!
+   post_integrate do |installer|
+       begin
+           expo_patch_react_imports!(installer)
+       rescue => e
+           Pod::UI.warn e
+       end
+   end

config = use_native_modules!
use_react_native!(

Adding Location Permissions to Info.plist

To ensure the app has the necessary permissions to access the device's location, you need to add the following keys to your Info.plist file:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to use your location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to use your location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to use your location</string>
Install Pods:
npx pod-install

Configuration for Android

Below is an example of how to modify your android/app/src/main/java/com/myapp/MainActivity.kt file:

package com.myapp
+ import expo.modules.ReactActivityDelegateWrapper
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate

/**
 * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
 */
override fun createReactActivityDelegate(): ReactActivityDelegate =
-   DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
+   ReactActivityDelegateWrapper(this, BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled))

Below is an example of how to modify your android/app/src/main/java/com/myapp/MainApplication.kt file:

package com.myapp

+ import android.content.res.Configuration
+ import expo.modules.ApplicationLifecycleDispatcher
+ import expo.modules.ReactNativeHostWrapper
import android.app.Application
import com.facebook.react.PackageList

class MainApplication : Application(), ReactApplication {
    override val reactNativeHost: ReactNativeHost =
+ object : DefaultReactNativeHost(this) {
+ ReactNativeHostWrapper(this, object : DefaultReactNativeHost(this) {

        override fun getPackages(): List<ReactPackage> =
            PackageList(this).packages.apply {
                // Packages that cannot be autolinked yet can be added manually here, for example:
                // add(MyReactNativePackage())
            }
        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
+ })
    }

    override val reactHost: ReactHost
-     get() = getDefaultReactHost(applicationContext, reactNativeHost)
+     get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost)

    override fun onCreate() {
        super.onCreate()
        // If you opted-in for the New Architecture, we load the native entry point for this app.
        load()

+     ApplicationLifecycleDispatcher.onApplicationCreate(this)
+    }

+   override fun onConfigurationChanged(newConfig: Configuration) {
+     super.onConfigurationChanged(newConfig)
+     ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig)
    }
}

Below is an example of how to modify your android/settings.gradle file:

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

+ apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle")
+ useExpoModules()

Adding Location Permissions to AndroidManifest.xml (Android)

To ensure the app has the necessary permissions to access the device's location, you need to add the following permissions to your AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myapp">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <application
        android:requestLegacyExternalStorage="true"
        android:usesCleartextTraffic="true"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:allowBackup="true"
        android:theme="@style/AppTheme">

        <!-- Other configurations -->

    </application>
</manifest>

Usage

Here's a basic example of how to use the component:

import React from 'react';
import { View } from 'react-native';
import { QiblaFinder } from 'react-native-qibla-finder';

const App = () => (
  <View style={{ flex: 1 }}>
    <QiblaFinder />
  </View>
);

export default App;

Props

PropTypeDefaultDescription
backgroundColorstringtransparentBackground color
styleStyleProp<ViewStyle>-Additional styles for the container
qiblaDirectionImagestringrequire('./assets/kaaba.png')Image for Qibla direction
qiblaDirectionImageStyleStyleProp<ImageStyle>-Styles for Qibla direction image
qiblaDirectionTextStyleStyleProp<TextStyle>-Styles for Qibla direction text
qiblaDirectionStyleStyleProp<ViewStyle>-Styles for Qibla direction container
compassDirectionStyleStyleProp<ViewStyle>-Styles for compass direction container
compassDirectionTextStyleStyleProp<TextStyle>-Styles for compass direction text
compassStyleStyleProp<ViewStyle>-Styles for compass container
compassImagestringrequire('./assets/compass.png')Image for compass
compassImageStyleStyleProp<ImageStyle>-Styles for compass image
kaabaImagestringrequire('./assets/kaaba.png')Image for Kaaba
kaabaStyleStyleProp<ViewStyle>-Styles for Kaaba container
showLoadingIndicatorbooleantrueWhether to show the loading indicator
loadingIndicatorSizenumber50Size of the loading indicator
loadingIndicatorColorstringblackColor of the loading indicator
showQiblaDirectionbooleantrueWhether to show the Qibla direction
showCompassDirectionbooleantrueWhether to show the compass direction
vibrateDisablebooleanfalseWhether to disable vibration
onError(error: string) => void-Callback function to handle errors

Example Usage

For more control and customization, see the following example:

import React from 'react';
import { View } from 'react-native';
import { QiblaFinder } from 'react-native-qibla-finder';

const App = () => (
  <View style={{ flex: 1 }}>
    <QiblaFinder
      backgroundColor='white'
      qiblaDirectionImage='path/to/custom-qibla-image.png'
      compassImage='path/to/custom-compass-image.png'
      showLoadingIndicator={true}
      loadingIndicatorSize={60}
      loadingIndicatorColor='blue'
      showQiblaDirection={true}
      showCompassDirection={true}
      vibrateDisable={false}
      onError={(error) => console.error('QiblaFinder Error: ', error)}
    />
  </View>
);

export default App;

Feedback

If you have any feedback, please reach out to us at dogankablan@hotmail.com.tr

1.1.2

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago