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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-game-services

v0.1.47

Published

RN lib

Readme

react-native-game-services - BETA

A React Native library that provides a unified API for integrating Game Center (iOS) and Google Play Games (Android) services. This library enables authentication, leaderboards, and score submission across both platforms.

⚠️ Beta Warning: This library is currently in beta. We recommend using it for testing and development purposes only—production use is not advised at this time.

Features

  • 🔐 Authentication - Sign in with Game Center (iOS) or Google Play Games (Android)
  • 🏆 Leaderboards - Display and manage leaderboards
  • 📊 Score Submission - Submit scores to leaderboards
  • Expo Support - Works with Expo managed workflow
  • 🚀 Turbo Modules - Built with React Native Turbo Modules for better performance
  • 🎖️ Achievements - To-Do

Installation

npm install react-native-game-services
# or
yarn add react-native-game-services

iOS Setup

The library automatically configures Game Center entitlements for you. No manual Xcode configuration is needed.

  1. Configure Game Center in App Store Connect:

    • Go to App Store Connect
    • Select your app (or create one)
    • Go to Growth & Marketing > Game Center
    • Enable Game Center to your app
  2. Configure plugin (Expo only):

    Add the plugin to your app.json (no configuration needed for iOS):

    {
      "expo": {
        "plugins": ["react-native-game-services"]
      }
    }

    After adding the plugin, rebuild your app:

    # For React Native projects
    # Rebuild the native iOS app
    
    # For Expo projects
    npx expo prebuild --clean

Android Setup

  1. Enable Google Play Games Services:

    • Go to Google Play Console
    • Select your app (or create one)
    • Go to Grow users > Play Game Services > Setup and management > Configuration
    • Get your App ID (called as Project ID) from the Play Game Services dashboard
  2. Configure the Android App ID:

    The library automatically configures the Android App ID. You have two options depending on your project type:

    Option A: React Native Projects

    Create an app.json file in your project root (if it doesn't exist) and add:

    {
      "react-native-game-services": {
        "android_app_id": "YOUR_GOOGLE_PLAY_GAMES_APP_ID"
      }
    }

    Option B: Expo Projects

    Add the plugin to your app.json:

    {
      "expo": {
        "plugins": [
          [
            "react-native-game-services",
            {
              "androidAppId": "YOUR_GOOGLE_PLAY_GAMES_APP_ID"
            }
          ]
        ]
      }
    }

    After configuring, rebuild your app:

    # For React Native projects
    # Rebuild the native Android app
    
    # For Expo projects
    npx expo prebuild --clean

Usage

Basic Example

import React, { useEffect, useState } from 'react';
import { View, Button, Text, Platform } from 'react-native';
import {
  initialize,
  isAuthenticated,
  signIn,
  showLeaderboard,
  submitScore,
} from 'react-native-game-services';

export default function App() {
  const [signedIn, setSignedIn] = useState(false);

  useEffect(() => {
    // Initialize Game Services (required for Android)
    initialize();

    // Check authentication status
    checkAuth();

    async function checkAuth() {
      const auth = await isAuthenticated();
      if (!auth) {
        try {
          await signIn();
          setSignedIn(true);
        } catch (error) {
          console.error('Sign in failed:', error);
        }
      } else {
        setSignedIn(true);
      }
    }
  }, []);

  const leaderboardId = Platform.select({
    ios: 'your-ios-leaderboard-id',
    android: 'your-android-leaderboard-id',
    default: 'default-leaderboard-id',
  });

  const handleSubmitScore = async () => {
    try {
      await submitScore(leaderboardId!, 1500);
      console.log('Score submitted successfully!');
    } catch (error) {
      console.error('Failed to submit score:', error);
    }
  };

  const handleShowLeaderboard = async () => {
    try {
      await showLeaderboard(leaderboardId!);
    } catch (error) {
      console.error('Failed to show leaderboard:', error);
    }
  };

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text>Game Services Example</Text>

      {signedIn ? (
        <>
          <Button title="Submit Score" onPress={handleSubmitScore} />
          <Button title="Show Leaderboard" onPress={handleShowLeaderboard} />
        </>
      ) : (
        <Text>Signing in...</Text>
      )}
    </View>
  );
}

API Reference

initialize()

Initializes the Game Services SDK. Required for Android, optional for iOS.

import { initialize } from 'react-native-game-services';

initialize();

isAuthenticated(): Promise<boolean>

Checks if the user is currently authenticated with Game Center (iOS) or Google Play Games (Android).

const authenticated = await isAuthenticated();
if (authenticated) {
  console.log('User is authenticated');
}

Returns: Promise<boolean> - true if authenticated, false otherwise

signIn(): Promise<void>

Initiates the sign-in flow for the user. On iOS, this will show the Game Center authentication UI if not already signed in. On Android, this will show the Google Play Games sign-in UI.

try {
  await signIn();
  console.log('Signed in successfully');
} catch (error) {
  console.error('Sign in failed:', error);
}

Returns: Promise<void>

Throws: Error if authentication fails

showLeaderboard(leaderboardId: string, timeSpan?: number): Promise<void>

Displays the native leaderboard UI for the specified leaderboard.

await showLeaderboard('your-leaderboard-id', 0);

Parameters:

  • leaderboardId (string, required) - The ID of the leaderboard to display
  • timeSpan (number, optional) - Time span filter:
    • 0 - All time (default)
    • 1 - Today
    • 2 - Week
    • 3 - Today and Week

Returns: Promise<void>

Throws: Error if the leaderboard cannot be displayed

submitScore(leaderboardId: string, score: number): Promise<void>

Submits a score to the specified leaderboard.

await submitScore('your-leaderboard-id', 1000);

Parameters:

  • leaderboardId (string, required) - The ID of the leaderboard to submit to
  • score (number, required) - The score value to submit

Returns: Promise<void>

Throws: Error if the score cannot be submitted

Requirements

  • React Native >= 0.81.0
  • iOS >= 12.0
  • Android API Level >= 21
  • For Expo: Expo SDK >= 54.0.0

Contributing

Contributions are welcome! Please read our Contributing Guide and Code of Conduct before submitting a pull request.

License

MIT


Made with ❤️ using create-react-native-library