PHPickerFilter
PHPickerFilter represents which kinds of items a photo picker shows, for example only images, only videos, or images without screenshots. Assign it to the filter of a PHPickerConfiguration.
The twelve predefined filters are read from the class. Three static methods combine them into new filters, and combinations can be nested.
You need to install @nacrejs/photos first. See PHPickerViewController for how, or see Core and capability packages.
Inheritance: NSObject → PHPickerFilter
Constructor
You can't create one with new. new PHPickerFilter() throws TypeError:
Illegal constructor: PHPickerFilter is created by the runtime, not by newYou get filters from the static properties and static methods below.
Static properties
All are read-only. Each one returns the same object on every read.
| Property | What it shows |
|---|---|
PHPickerFilter.imagesFilter | Images, including Live Photos |
PHPickerFilter.videosFilter | Videos |
PHPickerFilter.livePhotosFilter | Live Photos |
PHPickerFilter.depthEffectPhotosFilter | Photos with a depth effect (taken in Portrait mode) |
PHPickerFilter.burstsFilter | Bursts |
PHPickerFilter.panoramasFilter | Panoramas |
PHPickerFilter.screenshotsFilter | Screenshots |
PHPickerFilter.screenRecordingsFilter | Screen recordings |
PHPickerFilter.cinematicVideosFilter | Videos shot in Cinematic mode |
PHPickerFilter.slomoVideosFilter | Slow-motion videos |
PHPickerFilter.timelapseVideosFilter | Time-lapse videos |
PHPickerFilter.spatialMediaFilter | Spatial photos and spatial videos |
Static methods
| Method | Resulting filter |
|---|---|
PHPickerFilter.anyFilterMatchingSubfilters() | Matches any one of them |
PHPickerFilter.allFilterMatchingSubfilters() | Matches every one of them |
PHPickerFilter.notFilterOfSubfilter() | Doesn't match this one |
Instance methods
| Method | Description |
|---|---|
isEqual() | Whether two filters mean the same thing |
Comparing two filters
Compare two filters with isEqual(), not ===:
- The twelve predefined filters return the same object on every read, so
===works for them. - Combined filters are new objects every time. If you build the same combination twice,
===isfalseandisEqual()istrue. - Reading the configuration's
filterdoesn't return the object you assigned: the system stores a copy.
Examples
const config = new PHPickerConfiguration();
// Images, but no screenshots
config.filter = PHPickerFilter.allFilterMatchingSubfilters([
PHPickerFilter.imagesFilter,
PHPickerFilter.notFilterOfSubfilter(PHPickerFilter.screenshotsFilter),
]);Effect: A photo picker created with this configuration shows photos, but no screenshots and no videos. The on-screen effect is not verified in the simulator.
Corresponding iOS API
| ObjC | JS |
|---|---|
PHPickerFilter.imagesFilter | PHPickerFilter.imagesFilter |
[PHPickerFilter anyFilterMatchingSubfilters:@[a, b]] | PHPickerFilter.anyFilterMatchingSubfilters([a, b]) |
[PHPickerFilter allFilterMatchingSubfilters:@[a, b]] | PHPickerFilter.allFilterMatchingSubfilters([a, b]) |
[PHPickerFilter notFilterOfSubfilter:a] | PHPickerFilter.notFilterOfSubfilter(a) |
[a isEqual:b] | a.isEqual(b) |
See also
PHPickerConfiguration: the filter goes in itsfilter- Picking photos and saving them to the photo library