import { useProduct } from '@stackfront/react-native-shopify';
function ProductScreen({ handle }: { handle: string }) {
const {
product,
loading,
error,
refetch,
// variant engine
selectedVariant,
selectedOptions,
availableOptions, // one group per option: { name, values: [{ value, isSelected, isAvailable }] }
disabledOptions, // { optionName: [unavailableValue, ...] }
price, compareAtPrice, SKU, isAvailable,
selectOption, // (optionName, value) => void
resetSelections,
// quantity stepper (clamped 1..99 by default)
quantity,
incrementQuantity, decrementQuantity, setQuantity,
// actions
addToCart, // adds the resolved variant at `quantity`
isAddingToCart,
} = useProduct({ handle });
if (loading) return <Loading />;
if (error) return <Error message={error.message} />;
if (!product) return <NotFound />;
return (
<ScrollView>
<Text style={typography.h1}>{product.title}</Text>
<Price price={price ?? product.priceRange?.minVariantPrice} />
{compareAtPrice && <Price strike price={compareAtPrice} />}
{/* Option pills — render every declared value; grey out what the matrix
says is unreachable from the current selection (Shopify PDP style). */}
{availableOptions.map((option) => (
<View key={option.name}>
<Text>{option.name}</Text>
<View style={{ flexDirection: 'row' }}>
{option.values.map(({ value, isAvailable, isSelected }) => (
<Button
key={value}
title={value}
selected={isSelected}
disabled={!isAvailable}
onPress={() => selectOption(option.name, value)}
/>
))}
</View>
</View>
))}
{/* Quantity stepper + the one primary action */}
<Stepper
value={quantity}
onIncrease={incrementQuantity}
onDecrease={decrementQuantity}
/>
<Button
title={isAvailable ? 'Add to cart' : 'Sold out'}
disabled={!isAvailable || isAddingToCart}
onPress={addToCart}
/>
</ScrollView>
);
}