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
19 changes: 10 additions & 9 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react-native-harness": "^1.0.0-alpha.25",
"react-native-nitro-image": "workspace:*",
"react-native-nitro-web-image": "workspace:*",
"react-native-nitro-modules": "0.35.5",
"react-native-nitro-modules": "0.35.7",
"react-native-safe-area-context": "^5.6.0",
"react-native-screens": "^4.14.1"
},
Expand Down
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import { createStaticNavigation } from '@react-navigation/native'
import { CachePriorityTab } from './CachePriorityTab'
import { EmptyTab } from './EmptyTab'
import { FastImageTab } from './FastImageTab'
import { NitroImageTab } from './NitroImageTab'
Expand All @@ -17,6 +18,7 @@ const Tabs = createBottomTabNavigator({
Empty: EmptyTab,
FastImage: FastImageTab,
NitroImage: NitroImageTab,
CachePriority: CachePriorityTab,
},
})
const Navigation = createStaticNavigation(Tabs)
Expand Down
83 changes: 83 additions & 0 deletions example/src/CachePriorityTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { useCallback, useMemo, useState } from 'react'
import { Button, FlatList, StyleSheet, Text, View } from 'react-native'
import { NitroImage } from 'react-native-nitro-image'
import { createImageURLs } from './createImageURLs'

export function CachePriorityTab() {
const heroURL = useMemo(() => `https://picsum.photos/seed/hero/800`, [])
const thumbnailURLs = useMemo(() => createImageURLs(200), [])
const [heroNonce, setHeroNonce] = useState(0)

const thumbnailSources = useMemo(
() => thumbnailURLs.map((url) => ({ url })),
[thumbnailURLs],
)

const heroSource = useMemo(() => ({ url: heroURL }), [heroURL])

const renderItem = useCallback(
({ item: source }: { item: { url: string } }) => (
<NitroImage
image={source}
recyclingKey={source.url}
style={styles.thumb}
resizeMode="cover"
/>
),
[],
)

return (
<View style={styles.container}>
<Text style={styles.label}>Hero (no cachePriority)</Text>
<NitroImage
key={heroNonce}
image={heroSource}
cachePriority={2}
recyclingKey={`${heroURL}#${heroNonce}`}
style={styles.hero}
resizeMode="cover"
/>
<View style={styles.buttonRow}>
<Text style={styles.counter}>
Remounted: {heroNonce} • check logcat: 1 SET, {heroNonce} HITs
</Text>
<Button
title="Reload hero"
onPress={() => setHeroNonce((n) => n + 1)}
/>
</View>
<Text style={styles.label}>Thumbnails (no cachePriority)</Text>
<FlatList
numColumns={4}
windowSize={3}
data={thumbnailSources}
keyExtractor={(source) => source.url}
renderItem={renderItem}
/>
</View>
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
},
buttonRow: {
paddingHorizontal: 12,
paddingVertical: 8,
},
label: {
paddingHorizontal: 12,
paddingVertical: 6,
fontWeight: '600',
},
hero: {
width: '100%',
aspectRatio: 16 / 9,
},
thumb: {
width: '25%',
aspectRatio: 1,
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class HybridImageView(context: Context): HybridNitroImageViewSpec(), RecyclableV
field = value
}

override var cachePriority: Double? = null

override fun prepareForRecycle() {
onDisappear()
imageView.setImageBitmap(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HybridImageView: HybridNitroImageViewSpec {
resetImageBeforeLoad = recyclingKey != oldValue
}
}
var cachePriority: Double?

private func updateResizeMode() {
let mode = resizeMode ?? .cover
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading