How to use expo-task-manager - 10 common examples

To help you get started, we’ve selected a few expo-task-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo / apps / native-component-list / src / screens / Location / BackgroundLocationMapScreen.tsx View on Github external
);
  }
}

async function getSavedLocations() {
  try {
    const item = await AsyncStorage.getItem(STORAGE_KEY);
    return item ? JSON.parse(item) : [];
  } catch (e) {
    return [];
  }
}

TaskManager.defineTask(LOCATION_UPDATES_TASK, async ({ data: { locations } }: any) => {
  if (locations && locations.length > 0) {
    const savedLocations = await getSavedLocations();
    const newLocations = locations.map(({ coords }: any) => ({
      latitude: coords.latitude,
      longitude: coords.longitude,
    }));

    // tslint:disable-next-line no-console
    console.log(`Received new locations at ${new Date()}:`, locations);

    savedLocations.push(...newLocations);
    await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(savedLocations));

    locationEventsEmitter.emit('update', savedLocations);
  }
});
github expo / expo / apps / native-component-list / src / screens / Location / GeofencingScreen.tsx View on Github external
/>
          
          <button title="Center">
        
      
    );
  }
}

async function getSavedRegions(): Promise {
  const tasks = await TaskManager.getRegisteredTasksAsync();
  const task = tasks.find(({ taskName }) =&gt; taskName === GEOFENCING_TASK);
  return task ? task.options.regions : [];
}

TaskManager.defineTask(GEOFENCING_TASK, async ({ data: { region } }: { data: any }) =&gt; {
  const stateString = Location.GeofencingRegionState[region.state].toLowerCase();

  // tslint:disable-next-line no-console
  console.log(`${stateString} region ${region.identifier}`);

  await Notifications.presentLocalNotificationAsync({
    title: 'Expo Geofencing',
    body: `You're ${stateString} a region ${region.identifier}`,
    data: region,
  });
});

const styles = StyleSheet.create({
  screen: {
    flex: 1,
  },</button>
github expo / expo / home / screens / LocationDiagnosticsScreen.js View on Github external
);
  }
}

async function getSavedLocations() {
  try {
    const item = await AsyncStorage.getItem(STORAGE_KEY);
    return item ? JSON.parse(item) : [];
  } catch (e) {
    return [];
  }
}

if (Platform.OS !== 'android') {
  TaskManager.defineTask(LOCATION_UPDATES_TASK, async ({ data: { locations } }) =&gt; {
    if (locations &amp;&amp; locations.length &gt; 0) {
      const savedLocations = await getSavedLocations();
      const newLocations = locations.map(({ coords }) =&gt; ({
        latitude: coords.latitude,
        longitude: coords.longitude,
      }));

      savedLocations.push(...newLocations);
      await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(savedLocations));

      locationEventsEmitter.emit('update', savedLocations);
    }
  });
}

const styles = StyleSheet.create({
github overthq / Auxilium / packages / app / src / Root.tsx View on Github external
};

	const loadAssets = () =&gt; {
		const images = [
			require('../assets/Notify.png'),
			require('../assets/Help_Others.png'),
			require('../assets/Security.png')
		];
		images.map(image =&gt; Asset.fromModule(image).downloadAsync());
	};

	if (!fontsLoaded) return ;
	return ;
};

TaskManager.defineTask(LOCATION_TASK, ({ data, error }: any) =&gt; {
	if (error) console.log(error);
	if (data) {
		const { locations } = data;
		const {
			coords: { longitude, latitude }
		} = locations[0] as { coords: EmergencyCoordinates };
		setInterval(() =&gt; {
			Emergencies.managePushNotifications({ longitude, latitude });
		}, 10000);
	}
});

export default Root;
github expo / expo / apps / native-component-list / src / screens / BackgroundFetchScreen.tsx View on Github external
<button title="{">
      
    );
  }
}

TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () =&gt; {
  const now = Date.now();

  console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`);
  await AsyncStorage.setItem(LAST_FETCH_DATE_KEY, now.toString());

  return BackgroundFetch.Result.NewData;
});

const styles = StyleSheet.create({
  screen: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  button: {
    padding: 10,</button>
github expo / expo / home / screens / GeofencingScreen.js View on Github external
);
  }
}

async function getSavedRegions() {
  const tasks = await TaskManager.getRegisteredTasksAsync();
  const task = tasks.find(({ taskName }) =&gt; taskName === GEOFENCING_TASK);
  return task ? task.options.regions : [];
}

if (Platform.OS !== 'android') {
  TaskManager.defineTask(GEOFENCING_TASK, async ({ data: { region } }) =&gt; {
    const stateString = Location.GeofencingRegionState[region.state].toLowerCase();
    const body = `You're ${stateString} a region with latitude: ${region.latitude}, longitude: ${region.longitude} and radius: ${region.radius}m`;

    await Notifications.presentLocalNotificationAsync({
      title: 'Expo Geofencing',
      body,
      data: {
        ...region,
        notificationBody: body,
        notificationType: GEOFENCING_TASK,
      },
    });
  });
}

Notifications.addListener(({ data, remote }) =&gt; {
github expo / expo / packages / expo-background-fetch / src / BackgroundFetch.ts View on Github external
export async function registerTaskAsync(taskName: string, options: BackgroundFetchOptions = {}): Promise {
  if (!ExpoBackgroundFetch.registerTaskAsync) {
    throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync')
  }
  if (!TaskManager.isTaskDefined(taskName)) {
    throw new Error(
      `Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`
    );
  }
  await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
github Marwan01 / food-converter / node_modules / expo-background-fetch / build / BackgroundFetch.js View on Github external
export async function registerTaskAsync(taskName, options = {}) {
    if (!ExpoBackgroundFetch.registerTaskAsync) {
        throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync');
    }
    if (!TaskManager.isTaskDefined(taskName)) {
        throw new Error(`Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`);
    }
    await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
export async function unregisterTaskAsync(taskName) {
github Marwan01 / food-converter / node_modules / expo-background-fetch / src / BackgroundFetch.ts View on Github external
export async function registerTaskAsync(taskName: string, options: BackgroundFetchOptions = {}): Promise {
  if (!ExpoBackgroundFetch.registerTaskAsync) {
    throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync')
  }
  if (!TaskManager.isTaskDefined(taskName)) {
    throw new Error(
      `Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`
    );
  }
  await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
github expo / expo / packages / expo-background-fetch / build / BackgroundFetch.js View on Github external
export async function registerTaskAsync(taskName, options = {}) {
    if (!ExpoBackgroundFetch.registerTaskAsync) {
        throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync');
    }
    if (!TaskManager.isTaskDefined(taskName)) {
        throw new Error(`Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`);
    }
    await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
export async function unregisterTaskAsync(taskName) {

expo-task-manager

Expo module that provides support for tasks that can run in the background.

MIT
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis