Skip to content

Commit

Permalink
Pre-fill alt text with 10-million card post (#5377)
Browse files Browse the repository at this point in the history
  • Loading branch information
clavin authored Sep 17, 2024
1 parent 0414b95 commit 390279d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/components/dialogs/nuxs/TenMillion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ export function TenMillionInner({
uri,
width: WIDTH,
height: HEIGHT,
altText: _(
msg`A virtual card celebrating 10 million users on Bluesky for user #${i18n.number(
userNumber,
)}`,
),
},
],
})
Expand Down
15 changes: 9 additions & 6 deletions src/state/models/media/gallery.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import {makeAutoObservable, runInAction} from 'mobx'
import {ImageModel} from './image'
import {Image as RNImage} from 'react-native-image-crop-picker'
import {openPicker} from 'lib/media/picker'

import {getImageDim} from 'lib/media/manip'
import {openPicker} from 'lib/media/picker'
import {ImageInitOptions, ImageModel} from './image'

interface InitialImageUri {
uri: string
width: number
height: number
altText?: string
}

export class GalleryModel {
images: ImageModel[] = []

constructor(uris?: {uri: string; width: number; height: number}[]) {
constructor(
uris?: {uri: string; width: number; height: number; altText?: string}[],
) {
makeAutoObservable(this)

if (uris) {
Expand All @@ -33,7 +36,7 @@ export class GalleryModel {
return this.images.some(image => image.altText.trim() === '')
}

*add(image_: Omit<RNImage, 'size'>) {
*add(image_: ImageInitOptions) {
if (this.size >= 4) {
return
}
Expand Down Expand Up @@ -100,10 +103,10 @@ export class GalleryModel {
async addFromUris(uris: InitialImageUri[]) {
for (const uriObj of uris) {
this.add({
mime: 'image/jpeg',
height: uriObj.height,
width: uriObj.width,
path: uriObj.uri,
altText: uriObj.altText,
})
}
}
Expand Down
23 changes: 17 additions & 6 deletions src/state/models/media/image.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {Image as RNImage} from 'react-native-image-crop-picker'
import {makeAutoObservable, runInAction} from 'mobx'
import {POST_IMG_MAX} from 'lib/constants'
import * as ImageManipulator from 'expo-image-manipulator'
import {getDataUriSize} from 'lib/media/util'
import {openCropper} from 'lib/media/picker'
import {ActionCrop, FlipType, SaveFormat} from 'expo-image-manipulator'
import {makeAutoObservable, runInAction} from 'mobx'
import {Position} from 'react-avatar-editor'

import {logger} from '#/logger'
import {POST_IMG_MAX} from 'lib/constants'
import {openCropper} from 'lib/media/picker'
import {Dimensions} from 'lib/media/types'
import {getDataUriSize} from 'lib/media/util'
import {isIOS} from 'platform/detection'
import {logger} from '#/logger'

export interface ImageManipulationAttributes {
aspectRatio?: '4:3' | '1:1' | '3:4' | 'None'
Expand All @@ -19,6 +20,13 @@ export interface ImageManipulationAttributes {
flipVertical?: boolean
}

export interface ImageInitOptions {
path: string
width: number
height: number
altText?: string
}

const MAX_IMAGE_SIZE_IN_BYTES = 976560

export class ImageModel implements Omit<RNImage, 'size'> {
Expand All @@ -41,12 +49,15 @@ export class ImageModel implements Omit<RNImage, 'size'> {
}
prevAttributes: ImageManipulationAttributes = {}

constructor(image: Omit<RNImage, 'size'>) {
constructor(image: ImageInitOptions) {
makeAutoObservable(this)

this.path = image.path
this.width = image.width
this.height = image.height
if (image.altText !== undefined) {
this.setAltText(image.altText)
}
}

setRatio(aspectRatio: ImageManipulationAttributes['aspectRatio']) {
Expand Down
2 changes: 1 addition & 1 deletion src/state/shell/composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ComposerOpts {
mention?: string // handle of user to mention
openEmojiPicker?: (pos: DOMRect | undefined) => void
text?: string
imageUris?: {uri: string; width: number; height: number}[]
imageUris?: {uri: string; width: number; height: number; altText?: string}[]
}

type StateContext = ComposerOpts | undefined
Expand Down

0 comments on commit 390279d

Please sign in to comment.