← All Projects
Scientific Calculator

Scientific Calculator

Two calculators in one - rotate your device to unlock 30+ scientific operations

react
react-hooks
typescript
react-native
mobile
ui-ux
theme-system
app-hero

Problem

Most Android calculator apps split basic and scientific modes into separate apps, or expose scientific functions through a cramped button grid that's always visible. Users wanted both modes in a single app that adapted to orientation — showing a clean basic layout in portrait and unlocking the full scientific keyboard in landscape.

Stack Decisions

Six custom hooks, no third-party calc library

All calculator logic lives in purpose-built hooks: useCalculator (expression evaluation), useOrientation (layout mode), useTheme (persistence), useHistory (AsyncStorage log), useConverter (unit math), and useConstants (physics values). No external math library means full control over operator precedence and edge cases.

useWindowDimensions for orientation detection

Rather than listening to device orientation events (which require permissions on some Android versions), the layout switches based on the window aspect ratio. Width > height shows the scientific keyboard; portrait hides it. No permissions, no event listener cleanup.

AsyncStorage for history and theme

Both the calculation history and theme preference are single serializable values. AsyncStorage was the right fit — no schema, no migration, and reads are fast enough to restore state before the first render in most cases.

Challenges

01

Operator precedence without a parser

Implementing correct precedence (multiplication before addition) and chained operations without a formal expression tree required a two-pass evaluation: collect operands and operators, then apply precedence rules. Edge cases like percentage of a running total and double-negation took the most iteration.

02

DEG/RAD mode as global state

Switching between degrees and radians mid-calculation needs to affect the next trig operation without re-evaluating the current expression. Storing the mode in the hook's state and reading it at evaluation time — rather than baking it into the button labels — kept the button grid stateless.

03

Temperature unit conversion

Unlike length or weight (simple multiplication factors), Celsius↔Fahrenheit↔Kelvin conversions require affine transforms. The converter module handles temperature as a special case with a Celsius pivot rather than a generic scale factor, preventing silent errors from a unified formula.

Outcome

A single app handling basic and scientific modes, full calculation history, a unit converter with 6 categories and 40+ units, clipboard integration, and a physics constants panel — all in React Native with no native modules. The orientation-based mode switch was the most positively reviewed UX decision, cited as the reason users uninstalled competing apps.