---
title: "Paywall'da etkileşimli bir kilo hedefi grafiği göster"
description: "Her kullanıcının tahmini kilosunu bir paywall flow'unda grafik olarak göster. Kullanıcılar grafikte sürükleyerek herhangi bir haftanın kilosunu görebilir."
---

> For the complete documentation index, see [llms.txt](https://adapty.io/docs/tr/llms.txt).

> **AI agents**: to search Adapty docs faster and with fewer tokens, install the Adapty skills: `npx adapty skills install --yes`

Belirtilen ağırlık değerlerini bir paywall flow'unda grafik olarak göstermek için bu tarifi takip edin. Kullanıcı, onboarding flow'unda mevcut ve hedef kilosunu girer. C# kodunuz her iki değeri toplayıp native kodunuza gönderir. Grafik, uygulamanızla birlikte kullanıcının bir değerden diğerine haftalık ne kadar ilerleme sağlayabileceğini gösterir. Uygulamanız grafiği bir [özel element](flow-custom-elements) içinde native view olarak render eder. iOS'ta view Swift Charts kullanır. Android'de ise grafik bir grafik kütüphanesi olmadan çizilir.

Bu tarif, [iOS tarifi](custom-element-interactive-chart) ve [Android tarifi](android-custom-element-interactive-chart) içindeki flow kurulumunu ve native view'ları yeniden kullanır. Bu tarifin her adımı, bunlardan ne kopyalanacağını ve Unity projesinde ne farklı yapılacağını açıklar.

## Başlamadan önce \{#before-you-start\}

- Uygulamanızı Adapty Unity SDK 4.4 veya sonraki bir sürüme güncelleyin. Önceki SDK sürümleri, her özel öğe için [yedek içeriği](flow-custom-elements#set-fallback-content) gösterir.
- Uygulamanızı flow'ları [getirmek](unity-get-pb-paywalls) ve [görüntülemek](unity-present-paywalls) için yapılandırın.
- Uygulamanızı özel öğeler için yapılandırın; bunun için [Unity SDK ile özel öğeleri görüntüleme](unity-flow-custom-elements) kılavuzuna bakın. Bu tarif, söz konusu kılavuzdaki C# ve Java `CustomElements` sınıflarına kod ekler.
- iOS'ta grafik boyunca sürükleme özelliği iOS 17 veya sonrasını gerektirir. iOS 16'da kullanıcılar çizgiyi görebilir ancak üzerinde sürükleme yapamaz.

İki ayrı flow oluşturun — biri onboarding için, diğeri paywall için. Her birini bir [placement](placements)'a ekleyin. Bu tarifte yer alan kod, `weight_paywall` ID'li placement'tan paywall flow'unu getirir.

## 1. Onboarding flow'unu ve paywall flow'unu ayarlayın \{#1-set-up-the-onboarding-flow-and-the-paywall-flow\}

Her iki flow'u da [iOS tarifindeki](custom-element-interactive-chart#1-ask-for-the-current-and-goal-weight-in-the-onboarding-flow) 1. ve 2. adımlarda olduğu gibi ayarlayın: onboarding flow'unda iki **Number** girişi ve paywall flow'unda grafik için bir özel element.

## 2. Yerel kodu ekleyin \{#add-the-native-code\}

iOS ve Android tarifler, paywall flow'una bir çözümleyici (resolver) bağlar. Unity SDK'sında tek bir flow için çözümleyici API'si bulunmaz. Bunun yerine, uygulama genelindeki çözümleyiciniz ağırlık planını bir mağazadan okur ve C# kodunuz paywall flow'u açılmadan önce mağazayı doldurur.

### iOS

`Assets/Plugins/iOS` klasöründeki bir Swift dosyasına, [iOS tarifi](custom-element-interactive-chart#4-create-the-chart-view)'nin 4. adımındaki ağırlık planını ve grafik görünümünü ekleyin. Ardından ağırlık planı için bir depo, depoyu okuyan bir çözümleyici ve C# kodunuzun çağırdığı iki fonksiyon ekleyin. `RegisterCustomElements` başlatma sırasında çözümleyiciyi ayarlar, `SetWeightPlan` ise depoyu doldurur:

```swift showLineNumbers title="Assets/Plugins/iOS/CustomElements.swift"

// the weight plan that your C# code sends before the paywall flow opens
@MainActor
final class WeightPlanStore {
    var plan: WeightPlan?
}

struct CustomElementsResolver: AdaptyUICustomElementsResolver {
    let weightPlanStore: WeightPlanStore

    func view(
        forType type: String,
        id: String,
        context: AdaptyUICustomElementContext
    ) -> AnyView? {
        switch type {
        case "line_chart" where id == "weight_goal":
            guard #available(iOS 16.0, *), let plan = weightPlanStore.plan else {
                return nil // no weight plan: show the fallback
            }
            return AnyView(WeightGoalChart(entries: plan.entries))
        // the other cases of your resolver
        default:
            return nil
        }
    }
}

@MainActor let weightPlanStore = WeightPlanStore()

// Called once from C# at launch, before any flow is created.
@_cdecl("RegisterCustomElements")
public func RegisterCustomElements() {
    Task { @MainActor in
        AdaptyUI.setCustomElementsResolver(CustomElementsResolver(weightPlanStore: weightPlanStore))
    }
}

// Called from C# before the paywall flow opens.
@_cdecl("SetWeightPlan")
public func SetWeightPlan(_ currentWeight: Double, _ goalWeight: Double) {
    Task { @MainActor in
        weightPlanStore.plan = WeightPlan(currentWeight: currentWeight, goalWeight: goalWeight)
    }
}
```

### Android

`WeightPlan`, `WeightEntry` ve `WeightGoalChartView` sınıflarını [Android tarifi](android-custom-element-interactive-chart#4-create-the-chart-view)'nin 4. adımının **Java** sekmesinden kopyalayın. Her sınıfı `Assets/Plugins/Android` dizininde ayrı bir dosyaya kaydedin; örneğin `WeightPlan.java`. Her dosyaya `package com.example.app;` satırı ve ilgili sınıfın kullandığı import'ları ekleyin.

`CustomElements.java` dosyasında, ağırlık planını okuyan bir resolver tanımlayın ve C# kodunuz için bir `setWeightPlan` metodu ekleyin:

```java showLineNumbers title="Assets/Plugins/Android/CustomElements.java"
package com.example.app;

public final class CustomElements {
    // the weight plan that your C# code sends before the paywall flow opens
    private static volatile WeightPlan weightPlan;

    // Called once from C# at launch, before any flow is created.
    // This resolver doesn't use the context.
    public static void register(Context context) {
        AdaptyUI.setCustomElementsResolver((type, id) -> {
            WeightPlan plan = weightPlan;
            if ("line_chart".equals(type) && "weight_goal".equals(id) && plan != null) {
                return AdaptyCustomElementContent.view(
                        (viewContext, elementContext) -> new WeightGoalChartView(viewContext, plan.entries)
                );
            }
            return null; // no weight plan, or another custom element: show the fallback
        });
    }

    // Called from C# before the paywall flow opens.
    public static void setWeightPlan(double currentWeight, double goalWeight) {
        weightPlan = new WeightPlan(currentWeight, goalWeight);
    }
}
```

C# kodunuz mevcut ve hedef ağırlığı göndermediği sürece, resolver herhangi bir görünüm döndürmez ve kullanıcılar yedek paywall'ı görür.

## 3. C# kodunuzdan ağırlıkları gönderin \{#3-send-the-weights-from-your-c-code\}

C# `CustomElements` sınıfında, her iki ağırlığı da native kodunuza geçiren bir `SendWeightPlan` metodu ekleyin. Vurgulanan satırlar, [Unity kılavuzundaki](unity-flow-custom-elements#pass-the-resolver-to-the-sdk) sınıfa eklemeniz gerekenleri göstermektedir:

```csharp showLineNumbers title="Assets/Scripts/CustomElements.cs" {9-10,29-40}
using UnityEngine;

public static class CustomElements
{
#if UNITY_IOS && !UNITY_EDITOR
    [System.Runtime.InteropServices.DllImport("__Internal")]
    private static extern void RegisterCustomElements();

    [System.Runtime.InteropServices.DllImport("__Internal")]
    private static extern void SetWeightPlan(double currentWeight, double goalWeight);
#endif

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void Register()
    {
#if UNITY_IOS && !UNITY_EDITOR
        RegisterCustomElements();
#elif UNITY_ANDROID && !UNITY_EDITOR
        using (var player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        using (var activity = player.GetStatic<AndroidJavaObject>("currentActivity"))
        using (var context = activity.Call<AndroidJavaObject>("getApplicationContext"))
        using (var resolver = new AndroidJavaClass("com.example.app.CustomElements"))
        {
            resolver.CallStatic("register", context);
        }
#endif
    }

    // call before the paywall flow opens
    public static void SendWeightPlan(double currentWeight, double goalWeight)
    {
#if UNITY_IOS && !UNITY_EDITOR
        SetWeightPlan(currentWeight, goalWeight);
#elif UNITY_ANDROID && !UNITY_EDITOR
        using (var customElements = new AndroidJavaClass("com.example.app.CustomElements"))
        {
            customElements.CallStatic("setWeightPlan", currentWeight, goalWeight);
        }
#endif
    }
}
```

`FlowViewDidReceiveAnalyticEvent` metodunu kullanarak mevcut ağırlığı ve hedef ağırlığı, [Flow'lara veri aktarma](unity-flow-custom-tags#pass-the-bmi-to-the-paywall) sayfasındaki BMI örneğinde olduğu gibi onboarding flow'undan toplayın. `FlowViewDidDisappear` yalnızca uygulamanız onboarding flow'unu kapattıktan sonra çalışır; bu nedenle flow'u [Flow'ları ve paywallları kapatma](unity-handle-paywall-actions#close-flows-and-paywalls) sayfasında gösterildiği gibi **Close flow** eylemi üzerinde kapatın. Kullanıcı onboarding flow'unu son ekrandan kapattığında her iki ağırlığı da native kodunuza gönderin ve paywall flow'unu açın:

```csharp showLineNumbers title="Unity"
public void FlowViewDidDisappear(AdaptyUIFlowView view) {
    // The listener receives events from every flow. Reset `bodyAnswers` and
    // `reachedLastScreen` whenever a flow disappears, so that the paywall
    // doesn't open again when the user closes it.
    var answers = new Dictionary<string, string>(bodyAnswers);
    var finished = reachedLastScreen;
    bodyAnswers.Clear();
    reachedLastScreen = false;

    // Number inputs send their values as strings.
    if (!finished) return;
    if (!answers.TryGetValue("weight", out var currentText)
        || !double.TryParse(currentText, out var currentWeight)) return;
    if (!answers.TryGetValue("goal_weight", out var goalText)
        || !double.TryParse(goalText, out var goalWeight)) return;

    // the resolver reads the weights when the paywall flow opens
    CustomElements.SendWeightPlan(currentWeight, goalWeight);
    ShowWeightPaywall();
}

private void ShowWeightPaywall() {
    Adapty.GetFlow("weight_paywall", (flow, flowError) => {
        if (flowError != null) {
            // handle the error
            return;
        }

        AdaptyUI.CreateFlowView(flow, new AdaptyUICreateFlowViewParameters(), (view, viewError) => {
            if (viewError != null) {
                // handle the error
                return;
            }

            view.Present((presentError) => {
                if (presentError != null) {
                    // handle the error
                }
            });
        });
    });
}
```

## 4. Cihazda Test Edin \{#test-on-a-device\}

Her iki flow'u da [iOS](custom-element-interactive-chart#6-test-on-a-device) ve [Android](android-custom-element-interactive-chart#6-test-on-a-device) rehberlerindeki 6. adımda anlatıldığı gibi test edin. Yedek görünümü test etmek için resolver'ın `weight_goal` ID'si için herhangi bir view döndürmemesini sağlayın ve paywall flow'unu yeniden açın.

Grafik yerine neden yedek görünümün göründüğünü anlamak için Unity rehberinin [Cihazda Test Edin](unity-flow-custom-elements#test-on-a-device) bölümündeki talimatları izleyin.