Skip to content

Native filters

Native hooks forward filter objects from @media-sdk/core unchanged — same types and validation as web.

bash
pnpm add @media-sdk/core@^0.3.1 @media-sdk/native@^0.1.0 react

Hook forwarding

  • useMediaSearch accepts photoFiltersclient.searchPhotos({ ...params, photoFilters })
  • useMediaVideos accepts videoFiltersclient.searchVideos({ ...params, videoFilters })

Changing filters triggers a new search (prior request is aborted).

PhotoSearchFilters / VideoSearchFilters

ts
interface PhotoSearchFilters {
  orientation?: "landscape" | "portrait" | "square";
  size?: "large" | "medium" | "small";
  color?: PhotoColor | PixabayColor;
  category?: string;
  minWidth?: number;
  minHeight?: number;
  editorsChoice?: boolean;
  locale?: string;
}

VideoSearchFilters uses the same shape.

Capability-gated filter UI

Build filter controls only when the active provider supports them:

tsx
import { useMediaCapabilities, useMediaSearch } from "@media-sdk/native";

function SearchWithFilters({ query }: { query: string }) {
  const caps = useMediaCapabilities();
  const [orientation, setOrientation] = useState<"landscape" | "portrait">("landscape");

  const { data, loading } = useMediaSearch({
    query,
    photoFilters: caps.photoFilters.orientation
      ? { orientation }
      : undefined,
  });

  // render filters + results
}

Filter UI components are not included in @media-sdk/ui-native v0.1.0 — use Picker, segmented controls, or custom buttons in your app. The Expo example demonstrates orientation and size filters.

Error handling

CodeCause
UNSUPPORTED_FILTERFilter field not supported by active provider
INVALID_FILTER_VALUEValue rejected by provider (e.g. unsupported color)

Catch MediaError from hook error state or wrap custom client calls. See Error handling recipes and Core errors.

Provider filter matrix

FilterPexels photosPexels videosPixabay photosPixabay videos
orientation
size
color
category
minWidth / minHeight
editorsChoice
locale

Sourced from PexelsMediaClient.capabilities and PixabayMediaClient.capabilities in @media-sdk/core.