Skip to content

Commit 4fae7f9

Browse files
authored
PICNIC-610: Retina Assets on Desktop & Mobile (keybase#20785)
* Include @3x assets to all icons * New approach * Snapshots * Cleanup * Remove .keep file * Remove brackets around string
1 parent 9c7858c commit 4fae7f9

51 files changed

Lines changed: 3007 additions & 1870 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎shared/common-adapters/icon.constants-gen.tsx‎

Lines changed: 892 additions & 0 deletions
Large diffs are not rendered by default.

‎shared/common-adapters/icon.desktop.tsx‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,22 @@ class Icon extends Component<Props, void> {
163163
}
164164
}
165165

166-
const imgName = (name: string, ext: string, mult: number, prefix?: string, postfix?: string) =>
167-
`${prefix || ''}${resolveImageAsURL('icons', name)}${mult > 1 ? `@${mult}x` : ''}.${ext}${postfix ||
166+
const imgName = (
167+
name: string,
168+
ext: string,
169+
imagesDir: string,
170+
mult: number,
171+
prefix?: string,
172+
postfix?: string
173+
) =>
174+
`${prefix || ''}${resolveImageAsURL(imagesDir, name)}${mult > 1 ? `@${mult}x` : ''}.${ext}${postfix ||
168175
''} ${mult}x`
169176

170177
function iconTypeToSrcSet(type: IconType) {
171178
const ext = Shared.typeExtension(type)
172179
const name: string = (Styles.isDarkMode() && iconMeta[type].nameDark) || type
173-
return [1, 2].map(mult => imgName(name, ext, mult)).join(', ')
180+
const imagesDir = Shared.getImagesDir(type)
181+
return [1, 2, 3].map(mult => imgName(name, ext, imagesDir, mult)).join(', ')
174182
}
175183

176184
export function iconTypeToImgSet(imgMap: {[size: string]: string}, targetSize: number): any {

‎shared/common-adapters/icon.shared.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export function typeExtension(type: IconType): string {
4141
return iconMeta[type].extension || 'png'
4242
}
4343

44+
export function getImagesDir(type: IconType): string {
45+
return iconMeta[type].imagesDir || 'icons'
46+
}
47+
4448
export function fontSize(type: IconType): {fontSize: number} | null {
4549
const meta = iconMeta[type]
4650
if (!meta) {

‎shared/common-adapters/image.d.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import * as React from 'react'
22
import {StylesCrossPlatform} from '../styles'
33

4-
type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center' | 'repeat'
5-
64
export type Props = {
75
src: string
86
style?: any
97
onDragStart?: (e: React.SyntheticEvent) => void
108
onLoad?: (e: React.BaseSyntheticEvent) => void
11-
resizeMode?: ResizeMode
129
}
1310

1411
export type ReqProps = {
1512
src: any
1613
style?: StylesCrossPlatform | null
17-
resizeMode?: ResizeMode
1814
}
1915

2016
export default class Image extends React.Component<Props> {}

‎shared/constants/types/whats-new.tsx‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,3 @@ export type LastVersion = NoVersion
44
export type LastLastVersion = NoVersion
55
export type WhatsNewVersion = CurrentVersion | LastVersion | LastLastVersion | NoVersion
66
export type WhatsNewVersions = [CurrentVersion, LastVersion, LastLastVersion]
7-
8-
export type Feature = {
9-
primaryButtonText?: string
10-
secondaryButtonText?: string
11-
image?: string | null
12-
}
13-
14-
export type FeatureWithSeenState = Feature & {seen: boolean}

‎shared/desktop/yarn-helper/font.tsx‎

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ const commands = {
2626

2727
const paths = {
2828
iconfont: path.resolve(__dirname, '../../images/iconfont'),
29-
iconpng: path.resolve(__dirname, '../../images/icons'),
29+
iconPng: path.resolve(__dirname, '../../images/icons'),
30+
illustrationPng: path.resolve(__dirname, '../../images/illustrations'),
31+
releasePng: path.resolve(__dirname, '../../images/releases'),
3032
fonts: path.resolve(__dirname, '../../fonts'),
3133
webFonts: path.resolve(__dirname, '../../fonts-for-web'),
3234
webFontsCss: path.resolve(__dirname, '../../fonts-for-web/fonts_custom.styl'),
3335
iconConstants: path.resolve(__dirname, '../../common-adapters/icon.constants-gen.tsx'),
3436
iconCss: path.resolve(__dirname, '../../common-adapters/icon.css'),
3537
}
3638

39+
// Locations of all PNG assets to include in icon.constants.gen
40+
const pngAssetDirPaths = [
41+
{assetDirPath: paths.iconPng, insertFn: insertIconAssets},
42+
{assetDirPath: paths.illustrationPng, insertFn: insertIllustrationAssets},
43+
{assetDirPath: paths.releasePng, insertFn: insertReleaseAssets},
44+
]
45+
3746
const fontHeight = 1024
3847
const descentFraction = 16 // Source: https://icomoon.io/#docs/font-metrics
3948
const descent = fontHeight / descentFraction
@@ -239,8 +248,7 @@ ${Object.keys(rules)
239248
content: "\\${rules[name].toString(16)}";
240249
}`
241250
)
242-
.join('\n')}
243-
`
251+
.join('\n')}`
244252

245253
try {
246254
fs.writeFileSync(paths.webFontsCss, css, 'utf8')
@@ -256,26 +264,24 @@ const fontsGeneratedError = error => {
256264
process.exit(1)
257265
}
258266

259-
function updateIconConstants() {
260-
console.log('Generating icon constants')
261-
267+
function insertIconAssets(iconFiles) {
262268
const icons = {}
263269

264-
// Build constants for the png assests.
265-
const iconFiles = fs.readdirSync(paths.iconpng).filter(i => i.indexOf('@') === -1)
266270
// light
267271
iconFiles
268272
.filter(i => i.startsWith('icon-'))
269273
.forEach(i => {
270274
const shortName = i.slice(0, -4)
271275
icons[shortName] = {
272276
extension: i.slice(-3),
277+
imagesDir: `'icons'`,
273278
isFont: false,
274279
nameDark: undefined,
275280
require: `'../images/icons/${i}'`,
276281
requireDark: undefined,
277282
}
278283
})
284+
279285
// dark
280286
iconFiles
281287
.filter(i => i.startsWith('icon-dark-'))
@@ -290,6 +296,63 @@ function updateIconConstants() {
290296
icons[lightName].requireDark = `'../images/icons/${i}'`
291297
})
292298

299+
return icons
300+
}
301+
302+
function insertIllustrationAssets(illustrationFiles) {
303+
return illustrationFiles.reduce((prevIcons, i) => {
304+
const shortName = i.slice(0, -4)
305+
return {
306+
...prevIcons,
307+
[shortName]: {
308+
extension: i.slice(-3),
309+
imagesDir: `'illustrations'`,
310+
isFont: false,
311+
nameDark: undefined,
312+
require: `'../images/illustrations/${i}'`,
313+
requireDark: undefined,
314+
},
315+
}
316+
}, {})
317+
}
318+
319+
function insertReleaseAssets(releaseFiles) {
320+
return releaseFiles.reduce((prevIcons, i) => {
321+
const shortName = i.slice(0, -4)
322+
return {
323+
...prevIcons,
324+
[shortName]: {
325+
extension: i.slice(-3),
326+
imagesDir: `'releases'`,
327+
isFont: false,
328+
nameDark: undefined,
329+
require: `'../images/releases/${i}'`,
330+
requireDark: undefined,
331+
},
332+
}
333+
}, {})
334+
}
335+
336+
function updateIconConstants() {
337+
console.log('Generating icon constants (from the following directories)')
338+
console.log('\t*' + pngAssetDirPaths.map(({assetDirPath}) => assetDirPath).join('\n\t*'))
339+
340+
// Build constants for the png assests.
341+
const icons = pngAssetDirPaths.reduce((prevIcons, {assetDirPath, insertFn}) => {
342+
// Don't include @2x and @3x assets in icon-constants-gen.
343+
// They are included later in srcSet generation by icon.*.tsx
344+
//
345+
// On macOS (10.12+) Finder.app will no longer display .DS_Store files. Make sure they are not included here.
346+
const iconFiles = fs
347+
.readdirSync(assetDirPath)
348+
.filter(i => i.indexOf('@') === -1 && i.indexOf('DS_Store') === -1)
349+
const newIcons = insertFn(iconFiles)
350+
return {
351+
...prevIcons,
352+
...newIcons,
353+
}
354+
}, {})
355+
293356
// Build constants for iconfont svgs
294357
const svgFilenames = getSvgNames(false /* print skipped */)
295358
svgFilenames.reduce((_, {counter, name, size}) => {
@@ -307,6 +370,7 @@ function updateIconConstants() {
307370
extension?: string
308371
charCode?: number
309372
nameDark?: string
373+
imagesDir?: string
310374
require?: string
311375
requireDark?: string
312376
}
@@ -321,6 +385,7 @@ function updateIconConstants() {
321385
const meta = [
322386
icon.charCode ? [`charCode: 0x${icons[name].charCode.toString(16)}`] : [],
323387
icon.extension ? [`extension: '${icons[name].extension}'`] : [],
388+
icon.imagesDir ? [`imagesDir: ${icons[name].imagesDir}`] : [],
324389
icon.gridSize ? [`gridSize: ${icons[name].gridSize}`] : [],
325390
`isFont: ${icon.isFont}`,
326391
icon.nameDark ? [`nameDark: ${icons[name].nameDark}`] : [],
@@ -458,7 +523,7 @@ const setFontMetrics = () => {
458523
}
459524

460525
function unusedAssetes() {
461-
const allFiles = fs.readdirSync(paths.iconpng)
526+
const allFiles = fs.readdirSync(paths.iconPng)
462527

463528
// map of root name => [files]
464529
const images = {}

‎shared/fs/banner/system-file-manager-integration-banner/kext-permission-popup.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ type Props = {
99
openSecurityPrefs: () => void
1010
}
1111

12-
const securityPreferenceIllustration = require('../../../images/illustrations/security-preferences.png')
13-
1412
const Illustration = () => (
1513
<Kb.Box style={styles.illustrationContainer}>
16-
<Kb.Image style={styles.image} resizeMode="contain" src={securityPreferenceIllustration} />
14+
<Kb.Icon style={styles.image} type="illustration-security-preferences" />
1715
<Kb.Box
1816
style={Styles.collapseStyles([styles.highlight, {bottom: 49, height: 24, left: 36, width: 136}])}
1917
/>

shared/images/illustrations/bg-provisioning-blue.png renamed to shared/images/illustrations/illustration-bg-provisioning-blue.png

File renamed without changes.

shared/images/illustrations/bg-provisioning-blue@2x.png renamed to shared/images/illustrations/illustration-bg-provisioning-blue@2x.png

File renamed without changes.

shared/images/illustrations/bg-provisioning-blue@3x.png renamed to shared/images/illustrations/illustration-bg-provisioning-blue@3x.png

File renamed without changes.

0 commit comments

Comments
 (0)