Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions core/scripts/testing/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ const DEFAULT_PALETTE = 'light';
// Store existing theme set from the app initialization
const customTheme = window.Ionic?.config?.customTheme;
// Load the default tokens for the theme
const themeLoaded = import(`/themes/${themeName}/default.tokens.js`).then((defaultTokens) =>
buildTheme(defaultTokens.defaultTheme, customTheme, paletteName)
const themeLoaded = Promise.all([
import(`/themes/${themeName}/default.tokens.js`),
import('/themes/utils/theme.js'),
]).then(([defaultTokens, themeUtils]) =>
buildTheme(defaultTokens.defaultTheme, customTheme, paletteName, themeUtils)
);

/*
Expand Down Expand Up @@ -224,11 +227,13 @@ const DEFAULT_PALETTE = 'light';
}

// TODO(FW-6750): Determine if this function can be removed once the theme tokens can be imported directly into the test pages
function buildTheme(tokensTheme, customTheme, paletteName) {
function buildTheme(tokensTheme, customTheme, paletteName, themeUtils) {
let theme = tokensTheme;
// Merge with existing theme to preserve any customizations
// Merge with existing theme to preserve any customizations. A custom
// value replaces the theme's media query values for the same key, as
// it does in the app (refer to `mergeTheme`).
if (customTheme) {
theme = deepMerge(theme, customTheme);
theme = themeUtils.mergeTheme(theme, customTheme);
}

// If a specific palette is requested, modify the palette structure
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/divider/_divider.docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
* @prop --ion-divider-spacing-xlarge-margin-bottom: Bottom margin of the `xlarge` divider spacing
* @prop --ion-divider-spacing-xxlarge-margin-top: Top margin of the `xxlarge` divider spacing
* @prop --ion-divider-spacing-xxlarge-margin-bottom: Bottom margin of the `xxlarge` divider spacing
* @prop --ion-divider-thickness: Thickness of the divider line
* @prop --ion-divider-thickness: Thickness of the divider line. The ios theme changes it with screen density, so the line stays one screen pixel thick.
*/
9 changes: 8 additions & 1 deletion core/src/components/divider/divider.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import type { IonMargin } from '../../themes/themes.interfaces';
import type { IonMargin, IonMediaQuery } from '../../themes/themes.interfaces';

export type IonDividerRecipe = {
/** Color of the divider line. */
color?: string;

/**
* Thickness used inside media queries, such as a thinner line on denser screens.
* A `thickness` that a custom theme sets outside this key replaces the base
* theme's values here, so it applies on every screen.
*/
mediaQuery?: IonMediaQuery<Pick<IonDividerRecipe, 'thickness'>>;

/** Applies for each value of the `spacing` property, except `"none"`, which is always 0. */
spacing?: {
[K in Exclude<IonDividerSpacing, 'none'>]?: {
Expand Down
8 changes: 5 additions & 3 deletions core/src/components/divider/divider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ $spacings: xxsmall, xsmall, small, medium, large, xlarge, xxlarge;
display: block;

width: 100%;
height: var(--ion-divider-thickness);

border: none;
border-top-width: var(--ion-divider-thickness);
border-top-style: solid;
border-top-color: var(--ion-divider-color);

// A filled box instead of a border: WebKit skips a border thinner than one
// CSS pixel at some positions on the page.
background: var(--ion-divider-color);
}

// Divider Spacing
Expand Down
111 changes: 111 additions & 0 deletions core/src/components/item/test/hairlines/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<title>Item - Hairlines</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
/>
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
<script src="../../../../../scripts/testing/scripts.js"></script>
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
<style>
/* Stays above the tab bar while the list scrolls */
#shift-button {
bottom: 8px;
inset-inline-end: 16px;
}
</style>
</head>

<body>
<ion-app>
<ion-tabs>
<ion-tab tab="hairlines">
<div class="ion-page">
<ion-header>
<ion-toolbar>
<ion-title>Item - Hairlines</ion-title>
</ion-toolbar>
</ion-header>
<ion-content fullscreen id="content">
<button id="shift-button" slot="fixed">Shift: 0px</button>
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Item - Hairlines</ion-title>
</ion-toolbar>
</ion-header>
<div class="ion-padding">
<p>
Check in Safari on an iPhone or the iOS simulator. With the bug, the line between two items is missing
at some scroll positions, so the items run together.
</p>
<p>
Each tap on the <strong>Shift</strong> button moves the list down by a tenth of a pixel, so every line
lands on a new position.
</p>
</div>
<ion-list id="items"></ion-list>
</ion-content>
</div>
</ion-tab>

<ion-tab-bar slot="bottom">
<ion-tab-button tab="hairlines">
<ion-label>Hairlines</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</ion-app>

<script>
const items = document.getElementById('items');
for (let i = 1; i <= 50; i++) {
const item = document.createElement('ion-item');
item.innerHTML = `
<ion-grid>
<ion-row>
<ion-col>
<ion-label>Item ${i}</ion-label>
<ion-note>${(i * 397) % 1000}</ion-note>
</ion-col>
</ion-row>
</ion-grid>
`;
items.appendChild(item);
}

/**
* `shift` and `scroll` set the starting shift and scroll offset, in pixels,
* so an automated check can screenshot the lines at exact positions.
*/
const params = new URLSearchParams(location.search);
const scroll = parseFloat(params.get('scroll') || '0');
let shift = parseFloat(params.get('shift') || '0');

const spacer = document.createElement('div');
items.before(spacer);

const shiftButton = document.getElementById('shift-button');
const applyShift = () => {
spacer.style.height = `${shift}px`;
shiftButton.textContent = `Shift: ${shift}px`;
};
applyShift();

// Steps through 0 to 0.9px, then starts over.
shiftButton.addEventListener('click', () => {
shift = ((Math.round(shift * 10) + 1) % 10) / 10;
applyShift();
});

window.addEventListener('appload', async () => {
const el = await document.getElementById('content').getScrollElement();
el.scrollTop = scroll;
});
</script>
</body>
</html>
15 changes: 15 additions & 0 deletions core/src/themes/ios/default.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,21 @@ export const defaultTheme: DefaultTheme = {
IonDivider: {
color: '#e0e0e0',

// One screen pixel at each density, like native iOS separators.
mediaQuery: {
min: {
resolution: {
'2dppx': {
thickness: '0.5px',
},

'3dppx': {
thickness: '0.3334px',
},
},
},
},

spacing: {
xxsmall: {
margin: {
Expand Down
22 changes: 22 additions & 0 deletions core/src/themes/themes.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,28 @@ type Components = {
IonModal?: any;
};

/**
* Values a component uses inside media queries. The path builds the query:
* `min.resolution['2dppx']` applies inside `@media (min-resolution: 2dppx)`.
* The values set the same CSS variables as the component's own.
*
* A value set by a custom theme replaces the base theme's media query values
* for that key, so it applies on every screen.
*/
export type IonMediaQuery<T> = {
/** Applies when the screen is at least the given value. When several match, the largest wins. */
min?: {
/** Screen density, in screen pixels per CSS pixel. */
resolution?: { [K in IonMediaQueryResolution]?: T };
};
};

/**
* The screen densities a recipe can target. iPhones are 2x or 3x. Add a
* density when a component needs it.
*/
export type IonMediaQueryResolution = '2dppx' | '3dppx';

export type IonMargin = {
top?: string | number;
end?: string | number;
Expand Down
Loading
Loading