ronantakizawa/codereview-bench huggingface dataset:
Repository: NativeScript/NativeScript
File: packages/core/ui/core/view/view-common.ts (TypeScript)

Code before:
	set accessibilityState(value: AccessibilityState) {
		this.style.accessibilityState = value;
	}

	get accessibilityLiveRegion(): AccessibilityLiveRegion {
		return this.style.accessibilityLiveRegion;
	}
	set accessibilityLiveRegion(value: AccessibilityLiveRegion) {
		this.style.accessibilityLiveRegion = value;
	}

	get accessibilityLanguage(): string {
		return this.style.accessibilityLanguage;
	}
	set accessibilityLanguage(value: string) {
		this.style.accessibilityLanguage = value;
	}

	get accessibilityMediaSession(): boolean {
		return this.style.accessibilityMediaSession;
	}
	set accessibilityMediaSession(value: boolean) {
		this.style.accessibilityMediaSession = value;
	}

	get iOSAccessibilityAdjustsFontSize(): boolean {
		return this.style.iOSAccessibilityAdjustsFontSize;
	}
	set iOSAccessibilityAdjustsFontSize(value: boolean) {
		this.style.iOSAccessibilityAdjustsFontSize = value;
	}

	get iOSAccessibilityMinFontScale(): number {
		return this.style.iOSAccessibilityMinFontScale;
	}
	set iOSAccessibilityMinFontScale(value: number) {
		this.style.iOSAccessibilityMinFontScale = value;
	}

	get iOSAccessibilityMaxFontScale(): number {
		return this.style.iOSAccessibilityMaxFontScale;
	}
	set iOSAccessibilityMaxFontScale(value: number) {
		this.style.iOSAccessibilityMaxFontScale = value;
	}

	get automationText(): string {
		return this.accessibilityIdentifier;
	}

	set automationText(value: string) {

Review comment (suggestion):
```suggestion
	get iosAccessibilityAdjustsFontSize(): boolean {
```

Code after:
	set accessibilityState(value: AccessibilityState) {
		this.style.accessibilityState = value;
	}

	get accessibilityLiveRegion(): AccessibilityLiveRegion {
		return this.style.accessibilityLiveRegion;
	}
	set accessibilityLiveRegion(value: AccessibilityLiveRegion) {
		this.style.accessibilityLiveRegion = value;
	}

	get accessibilityLanguage(): string {
		return this.style.accessibilityLanguage;
	}
	set accessibilityLanguage(value: string) {
		this.style.accessibilityLanguage = value;
	}

	get accessibilityMediaSession(): boolean {
		return this.style.accessibilityMediaSession;
	}
	set accessibilityMediaSession(value: boolean) {
		this.style.accessibilityMediaSession = value;
	}

	get iosAccessibilityAdjustsFontSize(): boolean {
		return this.style.iosAccessibilityAdjustsFontSize;
	}
	set iosAccessibilityAdjustsFontSize(value: boolean) {
		this.style.iosAccessibilityAdjustsFontSize = value;
	}

	get iosAccessibilityMinFontScale(): number {
		return this.style.iosAccessibilityMinFontScale;
	}
	set iosAccessibilityMinFontScale(value: number) {
		this.style.iosAccessibilityMinFontScale = value;
	}

	get iosAccessibilityMaxFontScale(): number {
		return this.style.iosAccessibilityMaxFontScale;
	}
	set iosAccessibilityMaxFontScale(value: number) {
		this.style.iosAccessibilityMaxFontScale = value;
	}

	get automationText(): string {
		return this.accessibilityIdentifier;
	}

	set automationText(value: string) {
Repository: NativeScript/NativeScript
File: packages/core/ui/core/view/view-common.ts (TypeScript)

Code before:
		this.style.accessibilityState = value;
	}

	get accessibilityLiveRegion(): AccessibilityLiveRegion {
		return this.style.accessibilityLiveRegion;
	}
	set accessibilityLiveRegion(value: AccessibilityLiveRegion) {
		this.style.accessibilityLiveRegion = value;
	}

	get accessibilityLanguage(): string {
		return this.style.accessibilityLanguage;
	}
	set accessibilityLanguage(value: string) {
		this.style.accessibilityLanguage = value;
	}

	get accessibilityMediaSession(): boolean {
		return this.style.accessibilityMediaSession;
	}
	set accessibilityMediaSession(value: boolean) {
		this.style.accessibilityMediaSession = value;
	}

	get iOSAccessibilityAdjustsFontSize(): boolean {
		return this.style.iOSAccessibilityAdjustsFontSize;
	}
	set iOSAccessibilityAdjustsFontSize(value: boolean) {
		this.style.iOSAccessibilityAdjustsFontSize = value;
	}

	get iOSAccessibilityMinFontScale(): number {
		return this.style.iOSAccessibilityMinFontScale;
	}
	set iOSAccessibilityMinFontScale(value: number) {
		this.style.iOSAccessibilityMinFontScale = value;
	}

	get iOSAccessibilityMaxFontScale(): number {
		return this.style.iOSAccessibilityMaxFontScale;
	}
	set iOSAccessibilityMaxFontScale(value: number) {
		this.style.iOSAccessibilityMaxFontScale = value;
	}

	get automationText(): string {
		return this.accessibilityIdentifier;
	}

	set automationText(value: string) {
		this.accessibilityIdentifier = value;

Review comment (suggestion):
```suggestion
		return this.style.iosAccessibilityAdjustsFontSize;
```

Code after:
		this.style.accessibilityState = value;
	}

	get accessibilityLiveRegion(): AccessibilityLiveRegion {
		return this.style.accessibilityLiveRegion;
	}
	set accessibilityLiveRegion(value: AccessibilityLiveRegion) {
		this.style.accessibilityLiveRegion = value;
	}

	get accessibilityLanguage(): string {
		return this.style.accessibilityLanguage;
	}
	set accessibilityLanguage(value: string) {
		this.style.accessibilityLanguage = value;
	}

	get accessibilityMediaSession(): boolean {
		return this.style.accessibilityMediaSession;
	}
	set accessibilityMediaSession(value: boolean) {
		this.style.accessibilityMediaSession = value;
	}

	get iosAccessibilityAdjustsFontSize(): boolean {
		return this.style.iosAccessibilityAdjustsFontSize;
	}
	set iosAccessibilityAdjustsFontSize(value: boolean) {
		this.style.iosAccessibilityAdjustsFontSize = value;
	}

	get iosAccessibilityMinFontScale(): number {
		return this.style.iosAccessibilityMinFontScale;
	}
	set iosAccessibilityMinFontScale(value: number) {
		this.style.iosAccessibilityMinFontScale = value;
	}

	get iosAccessibilityMaxFontScale(): number {
		return this.style.iosAccessibilityMaxFontScale;
	}
	set iosAccessibilityMaxFontScale(value: number) {
		this.style.iosAccessibilityMaxFontScale = value;
	}

	get automationText(): string {
		return this.accessibilityIdentifier;
	}

	set automationText(value: string) {
		this.accessibilityIdentifier = value;
Repository: NativeScript/NativeScript
File: packages/core/accessibility/index.android.ts (TypeScript)

Code before:
		Application.off(Application.resumeEvent, updateAccessibilityServiceState);
	});

	Application.on(Application.resumeEvent, updateAccessibilityServiceState);

	return accessibilityServiceEnabled;
}

export function setupAccessibleView(view: View): void {
	updateAccessibilityProperties(view);
}

export function updateAccessibilityProperties(view: View): void {
	if (!view.nativeViewProtected) {
		return;
	}

	setAccessibilityDelegate(view);
	applyContentDescription(view);
}

export function sendAccessibilityEvent(view: View, eventType: AndroidAccessibilityEvent, text?: string): void {
	if (!isAccessibilityServiceEnabled()) {
		return;
	}

	const cls = `sendAccessibilityEvent(${view}, ${eventType}, ${text})`;

	const androidView = view.nativeViewProtected as android.view.View;
	if (!androidView) {
		if (Trace.isEnabled()) {
			Trace.write(`${cls}: no nativeView`, Trace.categories.Accessibility);
		}

		return;
	}

	if (!eventType) {
		if (Trace.isEnabled()) {
			Trace.write(`${cls}: no eventName provided`, Trace.categories.Accessibility);
		}

		return;
	}

	if (!isAccessibilityServiceEnabled()) {
		if (Trace.isEnabled()) {
			Trace.write(`${cls} - TalkBack not enabled`, Trace.categories.Accessibility);
		}

		return;

Review comment (suggestion):
No need to allocate a new array, `Set` has an iterator and should work out of the box with the for below.

Using `pendingViews.clear()` after the for loop instead of creating a new `Set` instance might help with GC too.

Code after:
		Application.off(Application.resumeEvent, updateAccessibilityServiceState);
	});

	Application.on(Application.resumeEvent, updateAccessibilityServiceState);

	return accessibilityServiceEnabled;
}

export function setupAccessibleView(view: View): void {
	updateAccessibilityProperties(view);
}

let updateAccessibilityPropertiesMicroTask;
let pendingViews = new Set<View>();
export function updateAccessibilityProperties(view: View) {
	if (!view.nativeViewProtected) {
		return;
	}

	pendingViews.add(view);
	if (updateAccessibilityPropertiesMicroTask) return;

	updateAccessibilityPropertiesMicroTask = true;
	Promise.resolve().then(() => {
		updateAccessibilityPropertiesMicroTask = false;
		let _pendingViews = Array.from(pendingViews);
		pendingViews = new Set();
		for (const view of _pendingViews) {
			if (!view.nativeViewProtected) continue;
			setAccessibilityDelegate(view);
			applyContentDescription(view);
		}
		_pendingViews = [];
	});
}

export function sendAccessibilityEvent(view: View, eventType: AndroidAccessibilityEvent, text?: string): void {
	if (!isAccessibilityServiceEnabled()) {
		return;
	}

	const cls = `sendAccessibilityEvent(${view}, ${eventType}, ${text})`;

	const androidView = view.nativeViewProtected as android.view.View;
	if (!androidView) {
		if (Trace.isEnabled()) {
			Trace.write(`${cls}: no nativeView`, Trace.categories.Accessibility);
		}

		return;
	}
Repository: NativeScript/NativeScript
File: packages/core/ui/styling/css-shadow.ts (TypeScript)

Code before:
/**
 * Matches whitespace except if the whitespace is contained in parenthesis - ex. rgb(a), hsl color.
 */
const PARTS_RE = /\s(?![^(]*\))/;

/**
 * Matches a Length value with or without a unit
 */
const LENGTH_RE = /^-?[0-9]+[a-zA-Z%]*?$/;

/**
 * Checks if the value is a Length or 0
 */
const isLength = (v) => v === '0' || LENGTH_RE.test(v);

export function parseCSSShorthand(value: string): {
	values: Array<CoreTypes.LengthType>;
	color: string;
	inset: boolean;
} {
	const parts = value.trim().split(PARTS_RE);
	const inset = parts.includes('inset');
	const first = parts[0];
	const last = parts[parts.length - 1];

	let color = 'black';
	if (first !== 'none') {
		if (first && !isLength(first) && first !== 'inset') {
			color = first;
		} else if (last && !isLength(last)) {
			color = last;
		}
	}
	const values = parts
		.filter((n) => n !== 'inset')
		.filter((n) => n !== color)
		.map((val) => {
			try {
				return Length.parse(val);
			} catch (err) {
				return CoreTypes.zeroLength;
			}
		});
	return {
		inset,
		color,
		values,
	};
}
/**
 * Parse a string into ShadowCSSValues

Review comment (suggestion):
I think short-circuiting and returning in case `first` is `none` is easier/cleaner to read than nesting ifs.

Code after:
import { Color } from '../../color';
import { CoreTypes } from '../../core-types';
import { parseCSSShorthand } from './css-utils';

export interface ShadowCSSValues {
	inset: boolean;
	offsetX: CoreTypes.LengthType;
	offsetY: CoreTypes.LengthType;
	blurRadius?: CoreTypes.LengthType;
	spreadRadius?: CoreTypes.LengthType;
	color: Color;
}

/**
 * Parse a string into ShadowCSSValues
 * Supports any valid css box/text shadow combination.
 *
 * inspired by https://github.com/jxnblk/css-box-shadow/blob/master/index.js (MIT License)
 *
 * @param value
 */
export function parseCSSShadow(value: string): ShadowCSSValues {
	const data = parseCSSShorthand(value);
	const [offsetX, offsetY, blurRadius, spreadRadius] = data.values;

	return {
		inset: data.inset,
		offsetX: offsetX,
		offsetY: offsetY,
		blurRadius: blurRadius,
		spreadRadius: spreadRadius,
		color: data.color ? new Color(data.color) : undefined,
	};
}
Repository: NativeScript/NativeScript
File: packages/core/ui/transition/page-transition.android.ts (TypeScript)

Code before:
import type { View } from '../core/view';
import { ViewBase } from '../core/view-base';
import { BackstackEntry } from '../frame';
import { isNumber } from '../../utils/types';
import { FadeTransition } from './fade-transition';
import { Transition } from '.';
import { getPageStartDefaultsForType, getRectFromProps, SharedTransition, SharedTransitionAnimationType, SharedTransitionEventData } from './shared-transition';
import { ImageSource } from '../../image-source';
import { ContentView } from '../content-view';
import { GridLayout } from '../layouts/grid-layout';
import { Screen } from '../../platform';
import { ExpandedEntry } from '../frame/fragment.transitions.android';
import { android as AndroidUtils } from '../../utils/native-helper';
// import { Image } from '../image';

@NativeClass
class SnapshotViewGroup extends android.view.ViewGroup {
	constructor(context: android.content.Context) {
		super(context);
		return global.__native(this);
	}
	public onMeasure(): void {
		this.setMeasuredDimension(0, 0);
	}
	public onLayout(): void {
		//
	}
}
class ContentViewSnapshot extends ContentView {
	createNativeView() {
		return new SnapshotViewGroup(this._context);
	}
}

@NativeClass
class CustomSpringInterpolator extends android.view.animation.AnticipateOvershootInterpolator {

Review comment (suggestion):
I think we can avoid using android-specific path and import module directly from `fragment.transitions`.

Code after:
import type { View } from '../core/view';
import { ViewBase } from '../core/view-base';
import { BackstackEntry } from '../frame';
import { isNumber } from '../../utils/types';
import { Transition } from '.';
import { getRectFromProps, SharedTransition, SharedTransitionAnimationType, SharedTransitionEventData } from './shared-transition';
import { ImageSource } from '../../image-source';
import { ContentView } from '../content-view';
import { GridLayout } from '../layouts/grid-layout';
import { Screen } from '../../platform';
import { ExpandedEntry } from '../frame/fragment.transitions.android';
import { android as AndroidUtils } from '../../utils/native-helper';
// import { Image } from '../image';

@NativeClass
class SnapshotViewGroup extends android.view.ViewGroup {
	constructor(context: android.content.Context) {
		super(context);
		return global.__native(this);
	}
	public onMeasure(): void {
		this.setMeasuredDimension(0, 0);
	}
	public onLayout(): void {
		//
	}
}
class ContentViewSnapshot extends ContentView {
	createNativeView() {
		return new SnapshotViewGroup(this._context);
	}
}

@NativeClass
class CustomSpringInterpolator extends android.view.animation.AnticipateOvershootInterpolator {
	getInterpolation(input: number) {
Repository: NativeScript/NativeScript
File: packages/core/ui/segmented-bar/index.ios.ts (TypeScript)

Code before:
import { Font } from '../styling/font';
import { SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsProperty, selectedBackgroundColorProperty } from './segmented-bar-common';
import { colorProperty, fontInternalProperty } from '../styling/style-properties';
import { Color } from '../../color';
import { Trace } from '../../trace';
import { Utils } from '../../index';
export * from './segmented-bar-common';

export class SegmentedBarItem extends SegmentedBarItemBase {
	public _update() {
		const parent = <SegmentedBar>this.parent;
		if (parent?.ios) {
			const tabIndex = parent.items.indexOf(this);
			let title = this.title;
			title = title === null || title === undefined ? '' : title;
			parent.ios.setTitleForSegmentAtIndex(title, tabIndex);
		}
	}
}

export class SegmentedBar extends SegmentedBarBase {
	nativeViewProtected: UISegmentedControl;
	private _selectionHandler: NSObject;

	createNativeView() {
		return UISegmentedControl.new();
	}

	initNativeView() {
		super.initNativeView();
		this._selectionHandler = SelectionHandlerImpl.initWithOwner(new WeakRef(this));

Review comment (refactor):
Better to use direct deep imports here instead of the "barrels" like `Utils`. So best to use iOSNativeHelper.
This is due to bundling - core needs to stick to direct imports everywhere inside core.

Code after:
import { Font } from '../styling/font';
import { SegmentedBarItemBase, SegmentedBarBase, selectedIndexProperty, itemsProperty, selectedBackgroundColorProperty } from './segmented-bar-common';
import { colorProperty, fontInternalProperty } from '../styling/style-properties';
import { Color } from '../../color';
import { Trace } from '../../trace';
import { SDK_VERSION } from '../../utils';
export * from './segmented-bar-common';

export class SegmentedBarItem extends SegmentedBarItemBase {
	public _update() {
		const parent = <SegmentedBar>this.parent;
		if (parent?.ios) {
			const tabIndex = parent.items.indexOf(this);
			let title = this.title;
			title = title === null || title === undefined ? '' : title;
			parent.ios.setTitleForSegmentAtIndex(title, tabIndex);
		}
	}
}

export class SegmentedBar extends SegmentedBarBase {
	nativeViewProtected: UISegmentedControl;
	private _selectionHandler: NSObject;

	createNativeView() {
		return UISegmentedControl.new();
	}

	initNativeView() {
		super.initNativeView();
		this._selectionHandler = SelectionHandlerImpl.initWithOwner(new WeakRef(this));
Repository: NativeScript/NativeScript
File: packages/core/utils/types.ts (TypeScript)

Code before:
	return typeof value === 'string' || value instanceof String;
}

export function isNumber(value: any): boolean {
	return typeof value === 'number' || value instanceof Number;
}

export function isBoolean(value: any): boolean {
	return typeof value === 'boolean' || value instanceof Boolean;
}

export function isFunction(value: any): boolean {
	if (!value) {
		return false;
	}

	return typeof value === 'function';
}

export function isObject(value: any): boolean {
	if (!value) {
		return false;
	}

	return typeof value === 'object';
}

export function isUndefined(value: any): boolean {
	return typeof value === 'undefined';
}

export function isDefined(value: any): boolean {
	return typeof value !== 'undefined';
}

export function isNullOrUndefined(value: any): boolean {
	return typeof value === 'undefined' || value === null;
}

export function verifyCallback(value: any) {
	if (value && !isFunction(value)) {
		throw new TypeError('Callback must be a valid function.');
	}
}

export function numberHasDecimals(value: number): boolean {
	return !(value % 1 === 0);
}

export function numberIs64Bit(value: number): boolean {
	return value < -Math.pow(2, 31) + 1 || value > Math.pow(2, 31) - 1;

Review comment (suggestion):
this is an invalid type guard.

an array, date, regex, class would also result in true but is not of type `Record<string, any>`

Code after:
	return typeof value === 'string' || value instanceof String;
}

export function isNumber(value: any): value is number {
	return typeof value === 'number' || value instanceof Number;
}

export function isBoolean(value: any): value is boolean {
	return typeof value === 'boolean' || value instanceof Boolean;
}

export function isFunction(value: any): value is Function {
	if (!value) {
		return false;
	}

	return typeof value === 'function';
}

export function isObject(value: any): value is Record<string,any> {
	if (!value) {
		return false;
	}

	return typeof value === 'object';
}

export function isUndefined(value: any): value is undefined {
	return typeof value === 'undefined';
}

export function isDefined(value: any): boolean {
	return typeof value !== 'undefined';
}

export function isNullOrUndefined(value: any): boolean {
	return typeof value === 'undefined' || value === null;
}

export function verifyCallback(value: any) {
	if (value && !isFunction(value)) {
		throw new TypeError('Callback must be a valid function.');
	}
}

export function numberHasDecimals(value: number): boolean {
	return !(value % 1 === 0);
}

export function numberIs64Bit(value: number): boolean {
	return value < -Math.pow(2, 31) + 1 || value > Math.pow(2, 31) - 1;
Repository: NativeScript/NativeScript
File: packages/core/ui/action-bar/index.ios.ts (TypeScript)

Code before:
	[colorProperty.setNative](color: Color) {
		const navBar = this.navBar;
		this.setColor(navBar, color);
	}

	[backgroundColorProperty.getDefault](): UIColor {
		return this._getBackgroundColor(this.navBar);
	}
	[backgroundColorProperty.setNative](color: UIColor | Color) {
		this._setBackgroundColor(this.navBar, color);
	}

	[backgroundImageProperty.getDefault](): UIImage {
		return this._getBackgroundImage(this.navBar);
	}
	[backgroundImageProperty.setNative](value: string | LinearGradient) {
		const navBar = this.navBar;

		this._createBackgroundUIImage(navBar, value, (image: UIImage) => {
			this._setBackgroundImage(navBar, image);
		});
	}

	[backgroundInternalProperty.getDefault](): UIColor {
		return null;
	}

	[flatProperty.setNative](value: boolean) {
		const navBar = this.navBar;
		if (navBar) {
			this.updateFlatness(navBar);
		}
	}

	[iosIconRenderingModeProperty.getDefault](): 'automatic' | 'alwaysOriginal' | 'alwaysTemplate' {
		return 'alwaysOriginal';
	}
	[iosIconRenderingModeProperty.setNative](value: 'automatic' | 'alwaysOriginal' | 'alwaysTemplate') {
		this.update();
	}

	[iosLargeTitleProperty.setNative](value: boolean) {
		if (!this.navBar) {
			return;
		}
		if (SDK_VERSION >= 11) {
			this.navBar.prefersLargeTitles = value;
		}
	}
}


Review comment (refactor):
@NathanWalker I think we shouldn't remove this. It overrides the default behaviour since ActionBar is a special case of view. That's why we handle backgroundColor.setNative and backgroundImage.setNative separately.

Code after:
	[colorProperty.setNative](color: Color) {
		const navBar = this.navBar;
		this.setColor(navBar, color);
	}

	[backgroundColorProperty.getDefault](): UIColor {
		return this._getBackgroundColor(this.navBar);
	}
	[backgroundColorProperty.setNative](color: UIColor | Color) {
		this._setBackgroundColor(this.navBar, color);
	}

	[backgroundImageProperty.getDefault](): UIImage {
		return this._getBackgroundImage(this.navBar);
	}
	[backgroundImageProperty.setNative](value: string | LinearGradient) {
		const navBar = this.navBar;

		this._createBackgroundUIImage(navBar, value, (image: UIImage) => {
			this._setBackgroundImage(navBar, image);
		});
	}

	[backgroundInternalProperty.getDefault](): UIColor {
		return null;
	}
	// @ts-ignore
	[backgroundInternalProperty.setNative](value: UIColor) {}

	[flatProperty.setNative](value: boolean) {
		const navBar = this.navBar;
		if (navBar) {
			this.updateFlatness(navBar);
		}
	}

	[iosIconRenderingModeProperty.getDefault](): 'automatic' | 'alwaysOriginal' | 'alwaysTemplate' {
		return 'alwaysOriginal';
	}
	[iosIconRenderingModeProperty.setNative](value: 'automatic' | 'alwaysOriginal' | 'alwaysTemplate') {
		this.update();
	}

	[iosLargeTitleProperty.setNative](value: boolean) {
		if (!this.navBar) {
			return;
		}
		if (SDK_VERSION >= 11) {
			this.navBar.prefersLargeTitles = value;
		}
	}