Lynx

GlobalPropsUpdatedObserver

A protocol (or interface) used to receive updates to GlobalProps.

Syntax

iOS

LynxBaseInspectorOwner.h
@protocol GlobalPropsUpdatedObserver <NSObject>

- (void)onGlobalPropsUpdated:(NSDictionary *)props;

@end

Android

GlobalPropsObserver.java
public interface GlobalPropsObserver {
  void onGlobalPropsUpdated(Map globalProps);
}

Parameters

  • globalProps: The updated GlobalProps, containing key-value pairs for all properties.

Usage Example

Implementation Steps

  1. Implement GlobalPropsUpdatedObserver.
  2. Get the LynxBaseInspectorOwner instance.
  3. Register GlobalPropsUpdatedObserver.

Code Example

iOS

TestGlobalPropsUpdatedObserver.h
#import <Lynx/LynxBaseInspectorOwner.h>

@interface TestGlobalPropsUpdatedObserver : NSObject <GlobalPropsUpdatedObserver>
@end
TestGlobalPropsUpdatedObserver.m
#import "TestGlobalPropsUpdatedObserver.h"

@implementation TestGlobalPropsUpdatedObserver

- (void)onGlobalPropsUpdated:(NSDictionary *)props {
  NSLog(@"onGlobalPropsUpdated: %@", props);
}

@end
ViewController.m
#import <Lynx/LynxView.h>
#import <Lynx/LynxBaseInspectorOwner.h>

#import "TestGlobalPropsUpdatedObserver.h"

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  // ...

  [lynxView updateGlobalPropsWithDictionary:@{@"key1": @"value1"}];
  id<LynxBaseInspectorOwner> owner = lynxView.baseInspectorOwner;
  TestGlobalPropsUpdatedObserver* observer =
      [[TestGlobalPropsUpdatedObserver alloc] init];
  [owner setGlobalPropsUpdatedObserver:observer];
  [lynxView updateGlobalPropsWithDictionary:@{@"key2": @"value2"}];
}

@end

Android

MainActivity.java
import android.util.Log;

import com.lynx.devtoolwrapper.GlobalPropsObserver;
import com.lynx.devtoolwrapper.LynxBaseInspectorOwner;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...

    registerGlobalPropsUpdatedObserver(lynxView);
  }

  private void registerGlobalPropsUpdatedObserver(LynxView lynxView) {
    LynxBaseInspectorOwner owner = lynxView.getBaseInspectorOwner();
    if (owner == null) {
      return;
    }
    lynxView.updateGlobalProps(new HashMap<String, Object>() {{
      put("key1", "value1");
    }});
    GlobalPropsObserver observer = new GlobalPropsObserver() {
      @Override
      public void onGlobalPropsUpdated(Map globalProps) {
        Log.i("MainActivity", "onGlobalPropsUpdated: " + globalProps.toString());
      }
    };
    owner.registerGlobalPropsUpdatedObserver(observer);
    lynxView.updateGlobalProps(new HashMap<String, Object>() {{
      put("key2", "value2");
    }});
  }
}

Compatibility

LCD tables only load in the browser

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.