Skip to content

ThreeCoins

A complete three-coin casting component for I Ching divination. Includes animated throws and result calculation.

import { ThreeCoins, ThrowHistory } from '@synchronicity/react-native';

Three coins are thrown to determine each line:

ResultValueLine TypeMeaning
2+2+26Old YinChanging broken line
2+2+37Young YangStable solid line
2+3+38Young YinStable broken line
3+3+39Old YangChanging solid line
<ThreeCoins />
const [throwing, setThrowing] = useState(false);
const handleThrow = () => setThrowing(true);
const handleComplete = (result: ThrowResult) => {
setThrowing(false);
console.log(result.value, result.lineType);
};
<ThreeCoins
throwing={throwing}
onPress={handleThrow}
onThrowComplete={handleComplete}
showValue
/>
<ThreeCoins
coins={['heads', 'tails', 'heads']}
showValue
/>
<ThreeCoins size="sm" />
<ThreeCoins size="md" />
<ThreeCoins size="lg" />

Display a history of throws:

<ThrowHistory
throws={[
{ coins: ['heads', 'heads', 'tails'], value: 8, lineType: 'yin' },
{ coins: ['heads', 'heads', 'heads'], value: 9, lineType: 'changing-yang' },
{ coins: ['tails', 'tails', 'heads'], value: 7, lineType: 'yang' },
]}
/>
const [throws, setThrows] = useState<ThrowResult[]>([]);
const [throwing, setThrowing] = useState(false);
const handleThrow = () => {
if (throws.length < 6) {
setThrowing(true);
}
};
const handleComplete = (result: ThrowResult) => {
setThrowing(false);
setThrows(prev => [...prev, result]);
};
<View>
<ThreeCoins
throwing={throwing}
onPress={handleThrow}
onThrowComplete={handleComplete}
showValue
disabled={throws.length >= 6}
/>
<Text>Line {throws.length + 1} of 6</Text>
<ThrowHistory throws={throws} />
</View>
PropTypeDefaultDescription
coins[CoinSide, CoinSide, CoinSide]-Current coin states
size'sm' | 'md' | 'lg''md'Size of coins
throwingbooleanfalseWhether coins are being thrown
throwDurationnumber800Animation duration (ms)
onThrowComplete(result: ThrowResult) => void-Called with result
onPress() => void-Press handler
disabledbooleanfalseDisable interaction
showValuebooleanfalseShow calculated value
styleViewStyle-Custom styles
PropTypeDefaultDescription
throwsThrowResult[]requiredArray of throw results
size'sm' | 'md''sm'Display size
styleViewStyle-Custom styles
type ThrowResult = {
coins: [CoinSide, CoinSide, CoinSide];
value: 6 | 7 | 8 | 9;
lineType: 'yin' | 'yang' | 'changing-yin' | 'changing-yang';
};