### Run Example App Locally Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md Commands to set up and run the example application for Expo WorkoutKit. Navigate to the `example` directory, install dependencies, and start the Expo development server. ```bash cd example npm install npx expo start ``` -------------------------------- ### Install Expo WorkoutKit using npm Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md This command installs the Expo WorkoutKit module directly from its GitHub repository. Ensure you have Node.js and npm installed. ```bash npm install https://github.com/rafiksh/expo-workoutkit ``` -------------------------------- ### Basic Usage of PreviewWorkoutButton in React Native Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md Demonstrates how to use the `PreviewWorkoutButton` component from `expo-workoutkit`. It takes a `workoutPlan` object to define the workout and an `onButtonPress` callback for handling button interactions. Requires `expo-workoutkit` to be installed. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; export default function App() { return ( { console.log('Workout button pressed:', message); }} style={{ height: 100 }} /> ); } ``` -------------------------------- ### PreviewWorkoutButton for Distance Goal Workout Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Illustrates configuring the PreviewWorkoutButton for a distance-based workout goal. This example sets up a button for a 10-kilometer cycling workout. It utilizes the 'expo-workoutkit' package and supports various distance units. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; function DistanceWorkout() { return ( { console.log('Cycling workout started:', nativeEvent.message); }} style={{ height: 48, marginVertical: 10 }} /> ); } ``` -------------------------------- ### PreviewWorkoutButton for Energy Goal Workout Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Shows how to set up the PreviewWorkoutButton for an energy-based workout goal, specifically targeting calorie burn. This example defines a workout plan for burning 500 kilocalories during cross-training. It requires 'expo-workoutkit' and specifies supported energy units. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; import type { WorkoutPlan } from 'expo-workoutkit'; function CalorieWorkout() { const energyWorkout: WorkoutPlan = { type: "goal", workout: { activity: "crossTraining", location: "indoor", goal: { type: "energy", value: 500, unit: "kilocalories", // "calories" | "kilocalories" | "joules" | "kilojoules" }, }, }; return ( { console.log('Energy workout triggered'); }} style={{ height: 55 }} /> ); } ``` -------------------------------- ### PreviewWorkoutButton for Pacer Workout Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Demonstrates the usage of PreviewWorkoutButton for a pacer workout, designed to help users maintain a specific pace. This example configures a 5K run at a 25-minute target pace. It requires the 'expo-workoutkit' library and handles the button press event. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; import type { PacerWorkout, WorkoutPlan } from 'expo-workoutkit'; function PacerWorkoutComponent() { const pacerPlan: WorkoutPlan = { type: "pacer", workout: { activity: "running", location: "outdoor", distance: { value: 5, unit: "kilometers", }, time: { value: 25, unit: "minutes", // "seconds" | "minutes" | "hours" }, }, }; const handlePacerPress = ({ nativeEvent }: { nativeEvent: { message: string } }) => { console.log('Pacer workout started:', nativeEvent.message); // WorkoutKit will guide user to maintain 5:00 min/km pace }; return ( ); } ``` -------------------------------- ### Time Goal Configuration for Workouts Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md Example of configuring a time-based goal for a workout plan in Expo WorkoutKit. It specifies the type as 'time' along with a numerical value and a unit (seconds, minutes, or hours). This is used within the `goal` property of workout plans. ```tsx goal: { type: "time", value: 30, unit: "minutes", // "seconds" | "minutes" | "hours" } ``` -------------------------------- ### Energy Goal Configuration for Workouts Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md Example of configuring an energy-based goal (e.g., calories burned) for a workout plan in Expo WorkoutKit. It specifies the type as 'energy' with a value and unit (calories, kilocalories, joules, or kilojoules). ```tsx goal: { type: "energy", value: 500, unit: "calories", // "calories" | "kilocalories" | "joules" | "kilojoules" } ``` -------------------------------- ### Supported Activity Types for Workouts (TypeScript) Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Illustrates how to define different workout plans using various activity types supported by HealthKit via the HKWorkoutActivityType enum. Examples cover cardio, sports, fitness, martial arts, and dance activities, each with a specific goal. ```tsx import type { HKWorkoutActivityType, WorkoutPlan } from 'expo-workoutkit'; // Cardio activities const runningWorkout: WorkoutPlan = { type: "goal", workout: { activity: "running", // "walking" | "cycling" | "swimming" location: "outdoor", goal: { type: "time", value: 30, unit: "minutes" }, }, }; // Sports activities const tennisWorkout: WorkoutPlan = { type: "goal", workout: { activity: "tennis", // "basketball" | "soccer" | "golf" | "hockey" location: "outdoor", goal: { type: "time", value: 60, unit: "minutes" }, }, }; // Fitness activities const yogaWorkout: WorkoutPlan = { type: "goal", workout: { activity: "yoga", // "pilates" | "strengthTraining" | "crossTraining" location: "indoor", goal: { type: "time", value: 45, unit: "minutes" }, }, }; // Martial arts activities const boxingWorkout: WorkoutPlan = { type: "goal", workout: { activity: "boxing", // "kickboxing" | "martialArts" location: "indoor", goal: { type: "time", value: 30, unit: "minutes" }, }, }; // Dance activities const danceWorkout: WorkoutPlan = { type: "goal", workout: { activity: "cardioDance", // "dance" | "socialDance" location: "indoor", goal: { type: "time", value: 40, unit: "minutes" }, }, }; ``` -------------------------------- ### Distance Goal Configuration for Workouts Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md Example of configuring a distance-based goal for a workout plan in Expo WorkoutKit. It includes the type 'distance', a numerical value, and a unit (meters, kilometers, yards, miles, or feet). This is part of the workout plan structure. ```tsx goal: { type: "distance", value: 5, unit: "kilometers", // "meters" | "kilometers" | "yards" | "miles" | "feet" } ``` -------------------------------- ### Define a Custom Workout Plan with Intervals Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md This code snippet defines a complex `customWorkout` plan for Expo WorkoutKit. It includes warmup, multiple work/recovery blocks with specified durations or distances, and a cooldown phase, allowing for detailed interval training setup. Requires `expo-workoutkit`. ```tsx const customWorkout = { type: "custom", workout: { activity: "running", location: "outdoor", displayName: "Interval Training", warmup: { goal: { type: "time", value: 10, unit: "minutes", }, }, blocks: [ { steps: [ { purpose: "work", step: { goal: { type: "distance", value: 1, unit: "kilometers", }, }, }, { purpose: "recovery", step: { goal: { type: "time", value: 2, unit: "minutes", }, }, }, ], iterations: 5, }, ], cooldown: { goal: { type: "time", value: 10, unit: "minutes", }, }, }, }; ``` -------------------------------- ### Display Multiple Workout Options in React Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Demonstrates how to create a scrollable list of different workout types (running goals, race pace, HIIT) using `WorkoutPlan` and `PreviewWorkoutButton`. It includes a handler for button presses. ```tsx import React from 'react'; import { ScrollView, View, Text } from 'react-native'; import { PreviewWorkoutButton } from 'expo-workoutkit'; import type { WorkoutPlan } from 'expo-workoutkit'; export default function WorkoutLibrary() { const workouts: Array<{ title: string; plan: WorkoutPlan }> = [ { title: "Quick 20-Minute Run", plan: { type: "goal", workout: { activity: "running", location: "outdoor", goal: { type: "time", value: 20, unit: "minutes" }, }, }, }, { title: "5K Race Pace", plan: { type: "pacer", workout: { activity: "running", location: "outdoor", distance: { value: 5, unit: "kilometers" }, time: { value: 22, unit: "minutes" }, }, }, }, { title: "HIIT Intervals", plan: { type: "custom", workout: { activity: "crossTraining", location: "indoor", displayName: "HIIT Session", warmup: { goal: { type: "time", value: 5, unit: "minutes" }, }, blocks: [ { steps: [ { purpose: "work", step: { goal: { type: "time", value: 30, unit: "seconds" } }, }, { purpose: "recovery", step: { goal: { type: "time", value: 30, unit: "seconds" } }, }, ], iterations: 10, }, ], cooldown: { goal: { type: "time", value: 5, unit: "minutes" }, }, }, }, }, ]; const handleWorkoutPress = (title: string) => ({ nativeEvent }: any) => { console.log(`${title} started:`, nativeEvent.message); }; return ( {workouts.map((workout, index) => ( {workout.title} ))} ); } ``` -------------------------------- ### Preview Workout Button for Custom Interval Training (TypeScript) Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Demonstrates the use of the PreviewWorkoutButton component to create a custom interval workout. This includes defining warmup, multiple work/recovery blocks with iterations, and cooldown phases. The component takes a WorkoutPlan object and various styling props. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; import type { CustomWorkout, WorkoutPlan, IntervalBlock } from 'expo-workoutkit'; function IntervalTraining() { const intervals: IntervalBlock[] = [ { steps: [ { purpose: "work", step: { goal: { type: "distance", value: 1, unit: "kilometers", }, }, }, { purpose: "recovery", step: { goal: { type: "time", value: 2, unit: "minutes", }, }, }, ], iterations: 5, // Repeat 5 times }, ]; const customWorkout: WorkoutPlan = { type: "custom", workout: { activity: "running", location: "outdoor", displayName: "5x1K Intervals", warmup: { goal: { type: "time", value: 10, unit: "minutes", }, }, blocks: intervals, cooldown: { goal: { type: "time", value: 5, unit: "minutes", }, }, }, }; return ( { console.log('Interval workout started'); }} style={{ height: 50 }} /> ); } ``` -------------------------------- ### Configure Swimming Workouts with Location in React Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Shows how to define `WorkoutPlan` objects for swimming activities, distinguishing between 'pool' and 'openWater' locations. It utilizes `PreviewWorkoutButton` to display these workout configurations. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; import type { WorkoutPlan, SingleGoalWorkout } from 'expo-workoutkit'; function SwimmingWorkout() { const poolSwim: WorkoutPlan = { type: "goal", workout: { activity: "swimming", location: "indoor", swimmingLocation: "pool", // "pool" | "openWater" | "unknown" goal: { type: "distance", value: 1000, unit: "meters", }, }, }; const openWaterSwim: WorkoutPlan = { type: "goal", workout: { activity: "swimming", location: "outdoor", swimmingLocation: "openWater", goal: { type: "time", value: 45, unit: "minutes", }, }, }; return ( <> ); } ``` -------------------------------- ### Preview Workout Button for Open Goal Workout (TypeScript) Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Shows how to use the PreviewWorkoutButton for an 'open goal' workout, which lacks a specific target like time or distance. This is useful for freeform exercise sessions. The component is configured with basic styling and an 'open' goal type. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; import type { WorkoutPlan } from 'expo-workoutkit'; function OpenGoalWorkout() { const openWorkout: WorkoutPlan = { type: "goal", workout: { activity: "walking", location: "outdoor", goal: { type: "open", // No specific target }, }, }; return ( { console.log('Open goal workout started'); }} style={{ height: 48 }} /> ); } ``` -------------------------------- ### TypeScript Type Definitions and Usage in Expo WorkoutKit Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt This snippet demonstrates the comprehensive TypeScript type definitions provided by Expo WorkoutKit for creating type-safe workout plans and handling events. It showcases how to define workout activities, goals, and props for the `PreviewWorkoutButton` component, ensuring compile-time safety. ```tsx import type { WorkoutPlan, HKWorkoutActivityType, HKWorkoutSessionLocationType, HKWorkoutSwimmingLocationType, WorkoutGoal, WorkoutStep, WorkoutAlert, IntervalStep, IntervalBlock, SingleGoalWorkout, PacerWorkout, CustomWorkout, PreviewWorkoutButtonProps, OnButtonPressEventPayload, } from 'expo-workoutkit'; // Type-safe workout creation function createTypeSafeWorkout(): WorkoutPlan { const activity: HKWorkoutActivityType = "running"; const location: HKWorkoutSessionLocationType = "outdoor"; const goal: WorkoutGoal = { type: "time", value: 30, unit: "minutes", }; const workout: SingleGoalWorkout = { activity, location, goal, }; return { type: "goal", workout, }; } // Type-safe event handling const handlePress = ({ nativeEvent }: { nativeEvent: OnButtonPressEventPayload }) => { const message: string = nativeEvent.message; console.log('Workout message:', message); }; // Type-safe props configuration const props: PreviewWorkoutButtonProps = { workoutPlan: createTypeSafeWorkout(), label: "Start Running", buttonColor: "#007AFF", textColor: "#ffffff", cornerRadius: 8, fontSize: 16, onButtonPress: handlePress, style: { height: 50 }, }; ``` -------------------------------- ### PreviewWorkoutButton for Time-Based Goal Workout Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Demonstrates using the PreviewWorkoutButton component to initiate a time-based goal workout. This button sends a workout plan with a specific time target to Apple Watch. It requires the 'expo-workoutkit' package and basic React Native components. ```tsx import { PreviewWorkoutButton } from 'expo-workoutkit'; import { View, Alert } from 'react-native'; export default function TimeBasedWorkout() { return ( { Alert.alert('Workout Started', message); }} style={{ height: 50 }} /> ); } ``` -------------------------------- ### PreviewWorkoutButton Component - Goal Workout Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt This component renders a native workout button for single-goal workouts. It allows users to initiate workouts with predefined targets for time, distance, or energy. ```APIDOC ## PreviewWorkoutButton Component - Goal Workout ### Description React component that renders a native workout button with WorkoutKit integration for single-goal workouts. ### Method N/A (Component) ### Endpoint N/A (Component) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body (Props) - **workoutPlan** (object) - Required - Defines the workout details including type, activity, location, and goal. - **type** (string) - Required - Must be "goal". - **workout** (object) - Required - Contains workout specifics. - **activity** (string) - Required - The type of athletic activity (e.g., "running", "cycling"). - **location** (string) - Required - The location of the workout (e.g., "outdoor", "indoor"). - **goal** (object) - Required - The objective of the workout. - **type** (string) - Required - The type of goal ("time", "distance", "energy"). - **value** (number) - Required - The target value for the goal. - **unit** (string) - Required - The unit for the goal value (e.g., "minutes", "kilometers", "kilocalories"). - **label** (string) - Required - The text displayed on the button. - **buttonColor** (string) - Optional - Background color of the button. - **textColor** (string) - Optional - Text color of the button. - **cornerRadius** (number) - Optional - The corner radius of the button. - **fontSize** (number) - Optional - The font size of the button text. - **onButtonPress** (function) - Required - Callback function when the button is pressed. Receives an event object with a `message` property. - **style** (object) - Optional - Custom styles for the button container. ### Request Example ```tsx { console.log(message); }} style={{ height: 50 }} /> ``` ### Response #### Success Response (N/A - Component triggers action) N/A #### Response Example N/A ``` -------------------------------- ### PreviewWorkoutButton Component - Energy Goal Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt This component is designed for energy-based workout goals, allowing users to set targets for calorie expenditure. ```APIDOC ## PreviewWorkoutButton Component - Energy Goal ### Description Component configured for calorie or energy-based workout goals. ### Method N/A (Component) ### Endpoint N/A (Component) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body (Props) - **workoutPlan** (object) - Required - Defines the workout details. - **type** (string) - Required - Must be "goal". - **workout** (object) - Required - Contains workout specifics. - **activity** (string) - Required - The type of athletic activity (e.g., "crossTraining"). - **location** (string) - Required - The location of the workout (e.g., "indoor"). - **goal** (object) - Required - The objective of the workout. - **type** (string) - Required - Must be "energy". - **value** (number) - Required - The target energy value. - **unit** (string) - Required - The unit for energy (e.g., "kilocalories", "calories", "joules", "kilojoules"). - **label** (string) - Required - The text displayed on the button. - **buttonColor** (string) - Optional - Background color of the button. - **textColor** (string) - Optional - Text color of the button. - **cornerRadius** (number) - Optional - The corner radius of the button. - **fontSize** (number) - Optional - The font size of the button text. - **onButtonPress** (function) - Required - Callback function when the button is pressed. - **style** (object) - Optional - Custom styles for the button container. ### Request Example ```tsx const energyWorkout = { type: "goal", workout: { activity: "crossTraining", location: "indoor", goal: { type: "energy", value: 500, unit: "kilocalories", // "calories" | "kilocalories" | "joules" | "kilojoules" }, }, }; { console.log('Energy workout triggered'); }} style={{ height: 55 }} /> ``` ### Response #### Success Response (N/A - Component triggers action) N/A #### Response Example N/A ``` -------------------------------- ### Import TypeScript Definitions from Expo WorkoutKit Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md This code demonstrates how to import various TypeScript types provided by the `expo-workoutkit` module. These types include `WorkoutPlan`, `HKWorkoutActivityType`, `WorkoutGoal`, and `PreviewWorkoutButtonProps` for enhanced type safety. ```tsx import type { WorkoutPlan, HKWorkoutActivityType, WorkoutGoal, PreviewWorkoutButtonProps } from 'expo-workoutkit'; ``` -------------------------------- ### Open Goal Configuration for Workouts Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md Configuration for an 'open' goal type in Expo WorkoutKit, which typically means the workout has no predefined target duration, distance, or energy expenditure. This is defined within the workout plan's `goal` property. ```tsx goal: { type: "open" } ``` -------------------------------- ### PreviewWorkoutButton Component - Distance Goal Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Configures the PreviewWorkoutButton for distance-based workout goals, supporting various distance units like kilometers, miles, meters, etc. ```APIDOC ## PreviewWorkoutButton Component - Distance Goal ### Description Component configured for distance-based workout goals with multiple distance unit options. ### Method N/A (Component) ### Endpoint N/A (Component) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body (Props) - **workoutPlan** (object) - Required - Defines the workout details. - **type** (string) - Required - Must be "goal". - **workout** (object) - Required - Contains workout specifics. - **activity** (string) - Required - The type of athletic activity (e.g., "cycling"). - **location** (string) - Required - The location of the workout (e.g., "outdoor"). - **goal** (object) - Required - The objective of the workout. - **type** (string) - Required - Must be "distance". - **value** (number) - Required - The target distance. - **unit** (string) - Required - The unit for the distance (e.g., "kilometers", "miles", "meters", "yards", "feet"). - **label** (string) - Required - The text displayed on the button. - **buttonColor** (string) - Optional - Background color of the button. - **textColor** (string) - Optional - Text color of the button. - **onButtonPress** (function) - Required - Callback function when the button is pressed. - **style** (object) - Optional - Custom styles for the button container. ### Request Example ```tsx { console.log('Cycling workout started:', nativeEvent.message); }} style={{ height: 48, marginVertical: 10 }} /> ``` ### Response #### Success Response (N/A - Component triggers action) N/A #### Response Example N/A ``` -------------------------------- ### PreviewWorkoutButton Component - Pacer Workout Source: https://context7.com/rafiksh/expo-workoutkit/llms.txt Enables the creation of pacer workouts, designed to help users maintain a consistent pace for a specified distance and time. ```APIDOC ## PreviewWorkoutButton Component - Pacer Workout ### Description Component for maintaining consistent pace over specified distance and time targets. ### Method N/A (Component) ### Endpoint N/A (Component) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body (Props) - **workoutPlan** (object) - Required - Defines the pacer workout details. - **type** (string) - Required - Must be "pacer". - **workout** (object) - Required - Contains workout specifics. - **activity** (string) - Required - The type of athletic activity (e.g., "running"). - **location** (string) - Required - The location of the workout (e.g., "outdoor"). - **distance** (object) - Required - The target distance for the pacer workout. - **value** (number) - Required - The distance value. - **unit** (string) - Required - The unit for distance (e.g., "kilometers", "miles"). - **time** (object) - Required - The target time for the pacer workout. - **value** (number) - Required - The time value. - **unit** (string) - Required - The unit for time (e.g., "minutes", "hours"). - **label** (string) - Required - The text displayed on the button. - **buttonColor** (string) - Optional - Background color of the button. - **textColor** (string) - Optional - Text color of the button. - **cornerRadius** (number) - Optional - The corner radius of the button. - **fontSize** (number) - Optional - The font size of the button text. - **onButtonPress** (function) - Required - Callback function when the button is pressed. - **style** (object) - Optional - Custom styles for the button container. ### Request Example ```tsx const pacerPlan = { type: "pacer", workout: { activity: "running", location: "outdoor", distance: { value: 5, unit: "kilometers", }, time: { value: 25, unit: "minutes", // "seconds" | "minutes" | "hours" }, }, }; const handlePacerPress = ({ nativeEvent }: { nativeEvent: { message: string } }) => { console.log('Pacer workout started:', nativeEvent.message); // WorkoutKit will guide user to maintain 5:00 min/km pace }; ``` ### Response #### Success Response (N/A - Component triggers action) N/A #### Response Example N/A ``` -------------------------------- ### Define a Goal Workout Plan Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md This code snippet defines a `goalWorkout` object, a type of workout plan for Expo WorkoutKit. It specifies the activity type, location, and a time-based goal. This structure is used to configure workouts within the module. ```tsx const goalWorkout = { type: "goal", workout: { activity: "running", location: "outdoor", goal: { type: "time", value: 30, unit: "minutes", }, }, }; ``` -------------------------------- ### Define a Pacer Workout Plan Source: https://github.com/rafiksh/expo-workoutkit/blob/main/README.md This code snippet defines a `pacerWorkout` object for Expo WorkoutKit. It configures a workout with a specific distance and time target, useful for maintaining a consistent pace. Requires the `expo-workoutkit` module. ```tsx const pacerWorkout = { type: "pacer", workout: { activity: "running", location: "outdoor", distance: { value: 5, unit: "kilometers", }, time: { value: 30, unit: "minutes", }, }, }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.