1 Commits

Author SHA1 Message Date
Arkaprabha Chakraborty
0a4f5a8b6e fix: input fields don't open keyboard if cursor is already present 2026-03-14 18:20:31 +05:30
8 changed files with 246 additions and 8 deletions

View File

@@ -86,6 +86,34 @@ You've successfully run and modified your React Native App. :partying_face:
If you're having issues getting the above steps to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
# Versioning (Single Source of Truth)
App versioning is centralized in [version.config.json](version.config.json).
## Commands
```sh
# Sync all targets from version.config.json
npm run version:sync
# Set exact version (and optional build number)
npm run version:set -- 1.2.0
npm run version:set -- 1.2.0 42
# Bump and auto-increment build number
npm run version:bump -- patch
npm run version:bump -- minor
npm run version:bump -- major
npm run version:bump -- build
```
## Synced targets
- `package.json``version`
- `app.json``version`, `android.versionCode`, `ios.buildNumber`
- `android/app/build.gradle``versionName`, `versionCode`
- `ios/Expensso.xcodeproj/project.pbxproj``MARKETING_VERSION`, `CURRENT_PROJECT_VERSION`
# Learn More
To learn more about React Native, take a look at the following resources:

View File

@@ -92,7 +92,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
versionName "0.1.2"
}
signingConfigs {
debug {

View File

@@ -1,4 +1,11 @@
{
"name": "Expensso",
"displayName": "Expensso"
"displayName": "Expensso",
"version": "0.1.2",
"android": {
"versionCode": 1
},
"ios": {
"buildNumber": "1"
}
}

View File

@@ -265,7 +265,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 0.1.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
@@ -294,7 +294,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 0.1.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",

View File

@@ -1,6 +1,6 @@
{
"name": "expensso",
"version": "0.1.1-alpha",
"version": "0.1.2",
"private": true,
"scripts": {
"android": "react-native run-android",
@@ -8,6 +8,9 @@
"lint": "eslint .",
"start": "react-native start",
"test": "jest",
"version:sync": "node scripts/version.js sync",
"version:set": "node scripts/version.js set",
"version:bump": "node scripts/version.js bump",
"build:release": "cd android && ./gradlew assembleRelease --no-daemon",
"build:release:aab": "cd android && ./gradlew bundleRelease --no-daemon"
},

186
scripts/version.js Normal file
View File

@@ -0,0 +1,186 @@
#!/usr/bin/env node
const fs = require('node:fs');
const path = require('node:path');
const rootDir = path.resolve(__dirname, '..');
const configPath = path.join(rootDir, 'version.config.json');
const packagePath = path.join(rootDir, 'package.json');
const appJsonPath = path.join(rootDir, 'app.json');
const androidGradlePath = path.join(rootDir, 'android', 'app', 'build.gradle');
const iosPbxprojPath = path.join(rootDir, 'ios', 'Expensso.xcodeproj', 'project.pbxproj');
function readJson(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
}
function writeJson(filePath, data) {
fs.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
}
function readVersionConfig() {
const config = readJson(configPath);
if (!isValidVersion(config.version)) {
throw new Error(`Invalid version in version.config.json: ${config.version}`);
}
if (!Number.isInteger(config.buildNumber) || config.buildNumber < 1) {
throw new Error(`Invalid buildNumber in version.config.json: ${config.buildNumber}`);
}
return config;
}
function isValidVersion(version) {
return /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(version);
}
function bumpVersion(version, type) {
const base = version.split('-')[0].split('+')[0];
const [major, minor, patch] = base.split('.').map(Number);
if (![major, minor, patch].every(Number.isInteger)) {
throw new Error(`Cannot bump invalid version: ${version}`);
}
if (type === 'major') {
return `${major + 1}.0.0`;
}
if (type === 'minor') {
return `${major}.${minor + 1}.0`;
}
if (type === 'patch') {
return `${major}.${minor}.${patch + 1}`;
}
throw new Error(`Unsupported bump type: ${type}`);
}
function replaceOrThrow(content, regex, replacement, targetName) {
if (!regex.test(content)) {
throw new Error(`Could not update ${targetName}. Expected pattern not found.`);
}
const updated = content.replace(regex, replacement);
return updated;
}
function syncToTargets({version, buildNumber}) {
const packageJson = readJson(packagePath);
packageJson.version = version;
writeJson(packagePath, packageJson);
const appJson = readJson(appJsonPath);
appJson.version = version;
appJson.android = {...(appJson.android || {}), versionCode: buildNumber};
appJson.ios = {...(appJson.ios || {}), buildNumber: String(buildNumber)};
writeJson(appJsonPath, appJson);
let gradle = fs.readFileSync(androidGradlePath, 'utf8');
gradle = replaceOrThrow(
gradle,
/versionCode\s+\d+/,
`versionCode ${buildNumber}`,
'android versionCode',
);
gradle = replaceOrThrow(
gradle,
/versionName\s+"[^"]+"/,
`versionName "${version}"`,
'android versionName',
);
fs.writeFileSync(androidGradlePath, gradle, 'utf8');
let pbxproj = fs.readFileSync(iosPbxprojPath, 'utf8');
pbxproj = replaceOrThrow(
pbxproj,
/MARKETING_VERSION = [^;]+;/g,
`MARKETING_VERSION = ${version};`,
'iOS MARKETING_VERSION',
);
pbxproj = replaceOrThrow(
pbxproj,
/CURRENT_PROJECT_VERSION = [^;]+;/g,
`CURRENT_PROJECT_VERSION = ${buildNumber};`,
'iOS CURRENT_PROJECT_VERSION',
);
fs.writeFileSync(iosPbxprojPath, pbxproj, 'utf8');
}
function saveConfig(config) {
writeJson(configPath, config);
}
function printUsage() {
console.log('Usage:');
console.log(' node scripts/version.js sync');
console.log(' node scripts/version.js set <version> [buildNumber]');
console.log(' node scripts/version.js bump <major|minor|patch|build>');
}
function main() {
const [, , command, arg1, arg2] = process.argv;
if (!command) {
printUsage();
process.exitCode = 1;
return;
}
if (command === 'sync') {
const config = readVersionConfig();
syncToTargets(config);
console.log(`Synced version ${config.version} (${config.buildNumber})`);
return;
}
if (command === 'set') {
if (!arg1 || !isValidVersion(arg1)) {
throw new Error('set requires a valid semver, e.g. 1.2.3');
}
const config = readVersionConfig();
const nextBuildNumber = arg2 ? Number(arg2) : config.buildNumber;
if (!Number.isInteger(nextBuildNumber) || nextBuildNumber < 1) {
throw new Error('buildNumber must be a positive integer');
}
const next = {version: arg1, buildNumber: nextBuildNumber};
saveConfig(next);
syncToTargets(next);
console.log(`Set version to ${next.version} (${next.buildNumber})`);
return;
}
if (command === 'bump') {
if (!arg1 || !['major', 'minor', 'patch', 'build'].includes(arg1)) {
throw new Error('bump requires one of: major, minor, patch, build');
}
const config = readVersionConfig();
const next = {
version: arg1 === 'build' ? config.version : bumpVersion(config.version, arg1),
buildNumber: config.buildNumber + 1,
};
saveConfig(next);
syncToTargets(next);
console.log(`Bumped to ${next.version} (${next.buildNumber})`);
return;
}
printUsage();
process.exitCode = 1;
}
try {
main();
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}

View File

@@ -27,10 +27,12 @@ import {
StyleSheet,
TouchableOpacity,
Pressable,
Platform,
} from 'react-native';
import BottomSheet, {
BottomSheetBackdrop,
BottomSheetScrollView,
BottomSheetTextInput,
BottomSheetView,
type BottomSheetBackdropProps,
} from '@gorhom/bottom-sheet';
@@ -271,8 +273,6 @@ export interface BottomSheetInputProps {
autoFocus?: boolean;
}
import {TextInput} from 'react-native';
export const BottomSheetInput: React.FC<BottomSheetInputProps> = ({
label,
value,
@@ -287,6 +287,13 @@ export const BottomSheetInput: React.FC<BottomSheetInputProps> = ({
const theme = useTheme();
const {colors, typography, shape, spacing} = theme;
const [focused, setFocused] = React.useState(false);
const inputRef = React.useRef<React.ComponentRef<typeof BottomSheetTextInput>>(null);
const handlePressIn = React.useCallback(() => {
if (Platform.OS === 'android' && focused) {
inputRef.current?.focus();
}
}, [focused]);
const borderColor = error
? colors.error
@@ -325,7 +332,8 @@ export const BottomSheetInput: React.FC<BottomSheetInputProps> = ({
{prefix}
</Text>
)}
<TextInput
<BottomSheetTextInput
ref={inputRef}
style={{
flex: 1,
...typography.bodyLarge,
@@ -340,6 +348,8 @@ export const BottomSheetInput: React.FC<BottomSheetInputProps> = ({
keyboardType={keyboardType}
multiline={multiline}
autoFocus={autoFocus}
showSoftInputOnFocus
onPressIn={handlePressIn}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
/>

4
version.config.json Normal file
View File

@@ -0,0 +1,4 @@
{
"version": "0.1.2",
"buildNumber": 1
}