/*
 * Copyright 2018-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.litho;

import com.facebook.yoga.YogaConfig;
import com.facebook.yoga.YogaNode;
import javax.annotation.Nullable;

/** A helper class that defines a configurable sizes for ComponentsPools. */
public class NodeConfig {

  public interface YogaNodeFactory {
    @Nullable
    YogaNode create(YogaConfig config);
  }

  public interface InternalNodeFactory {
    InternalNode create(ComponentContext componentContext);
  }

  /**
   * Custom factory for Yoga nodes. Used to enable direct byte buffers to set Yoga style properties
   * (rather than JNI)
   */
  public static volatile @Nullable YogaNodeFactory sYogaNodeFactory = null;

  /** Factory to create custom InternalNodes for Components. */
  public static volatile @Nullable InternalNodeFactory sInternalNodeFactory = null;

  private static final YogaConfig sYogaConfig = new YogaConfig();
  private static final Object sYogaConfigLock = new Object();

  static {
    sYogaConfig.setUseWebDefaults(true);
  }

  @Nullable
  static YogaNode createYogaNode() {
    return sYogaNodeFactory != null
        ? sYogaNodeFactory.create(sYogaConfig)
        : YogaNode.create(sYogaConfig);
  }

  /**
   * Toggles a Yoga setting on whether to print debug logs to adb.
   *
   * @param enable whether to print logs or not
   */
  public static void setPrintYogaDebugLogs(boolean enable) {
    synchronized (sYogaConfigLock) {
      sYogaConfig.setPrintTreeFlag(enable);
    }
  }

  /** Allows access to the internal YogaConfig instance */
  public static YogaConfig getYogaConfig() {
    return sYogaConfig;
  }

}

@@ -626,16 +626,53 @@
 litho;%0A%0A
+import androidx.annotation.Nullable;%0A
 import c
@@ -738,42 +738,8 @@
 ode;
-%0Aimport javax.annotation.Nullable;
 %0A%0A/*
@@ -1240,31 +1240,24 @@
 aNodeFactory
- = null
 ;%0A%0A  /** Fac
@@ -1390,15 +1390,8 @@
 tory
- = null
 ;%0A%0A 
@@ -1458,70 +1458,8 @@
 g();
-%0A  private static final Object sYogaConfigLock = new Object();
 %0A%0A  
@@ -1562,32 +1562,30 @@
 ode() %7B%0A    
-return s
+final 
 YogaNodeFact
@@ -1592,36 +1592,66 @@
 ory 
-!= null%0A        ? sYogaNodeF
+factory = sYogaNodeFactory;%0A    return factory != null ? f
 acto
@@ -1676,16 +1676,8 @@
 fig)
-%0A       
  : Y
@@ -1858,16 +1858,29 @@
  static 
+synchronized 
 void set
@@ -1920,47 +1920,8 @@
 ) %7B%0A
-    synchronized (sYogaConfigLock) %7B%0A  
     
@@ -1962,14 +1962,8 @@
 e);%0A
-    %7D%0A
   %7D%0A
@@ -2095,11 +2095,10 @@
 ig;%0A  %7D%0A
-%0A
 %7D%0A

Fix threading warning and simplify NodeConfig